Statistics
| Revision:

svn-gvsig-desktop / branches / Mobile_Compatible_Hito_1 / libDXF / src / org / cresques / px / dxf / DxfCalXtru.java @ 21930

History | View | Annotate | Download (3.96 KB)

1
/*
2
 * Cresques Mapping Suite. Graphic Library for constructing mapping applications.
3
 *
4
 * Copyright (C) 2004-5.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
 *
20
 * For more information, contact:
21
 *
22
 * cresques@gmail.com
23
 */
24
package org.cresques.px.dxf;
25

    
26
import org.cresques.geo.Point2DZ;
27

    
28
/**
29
 * La clase DxfCalXtru se emplea para aplicar los par?metros de extrusi?n de las
30
 * entidades de un DXF. Esta transformaci?n provoca alteraciones en las coordenadas de
31
 * estos elementos.
32
 * @author jmorell
33
 */
34
public class DxfCalXtru {
35
    
36
    /**
37
     * Aplica a un punto en 3D sus correspondientes par?metros de extrusi?n.
38
     * @param coord_in, punto antes de aplicar la extrusi?n.
39
     * @param xtru, par?metros de extrusi?n en X, en Y y en Z.
40
     * @return Point3D, punto 3D afectado de extrusi?n.
41
     */
42
    public static Point2DZ CalculateXtru(Point2DZ coord_in, Point2DZ xtru) {
43
        Point2DZ coord_out = new Point2DZ();
44

    
45
        double dxt0 = 0D;
46
        double dyt0 = 0D;
47
        double dzt0 = 0D;
48
        double dvx1;
49
        double dvx2;
50
        double dvx3;
51
        double dvy1;
52
        double dvy2;
53
        double dvy3;
54
        double dmod;
55
        double dxt;
56
        double dyt;
57
        double dzt;
58

    
59
        double aux = 1D / 64D; //LWS
60
        double aux1 = Math.abs(xtru.getX());
61
        double aux2 = Math.abs(xtru.getY());
62

    
63
        dxt0 = coord_in.getX();
64
        dyt0 = coord_in.getY();
65
        dzt0 = coord_in.getZ();
66

    
67
        double xtruX;
68
        double xtruY;
69
        double xtruZ;
70
        xtruX = xtru.getX();
71
        xtruY = xtru.getY();
72
        xtruZ = xtru.getZ();
73

    
74
        if ((aux1 < aux) && (aux2 < aux)) {
75
            dmod = Math.sqrt((xtruZ * xtruZ) + (xtruX * xtruX));
76
            dvx1 = xtruZ / dmod;
77
            dvx2 = 0;
78
            dvx3 = -xtruX / dmod;
79
        } else {
80
            dmod = Math.sqrt((xtruY * xtruY) + (xtruX * xtruX));
81
            dvx1 = -xtruY / dmod;
82
            dvx2 = xtruX / dmod;
83
            dvx3 = 0;
84
        }
85

    
86
        dvy1 = (xtruY * dvx3) - (xtruZ * dvx2);
87
        dvy2 = (xtruZ * dvx1) - (xtruX * dvx3);
88
        dvy3 = (xtruX * dvx2) - (xtruY * dvx1);
89

    
90
        dmod = Math.sqrt((dvy1 * dvy1) + (dvy2 * dvy2) + (dvy3 * dvy3));
91

    
92
        dvy1 = dvy1 / dmod;
93
        dvy2 = dvy2 / dmod;
94
        dvy3 = dvy3 / dmod;
95

    
96
        dxt = (dvx1 * dxt0) + (dvy1 * dyt0) + (xtruX * dzt0);
97
        dyt = (dvx2 * dxt0) + (dvy2 * dyt0) + (xtruY * dzt0);
98
        dzt = (dvx3 * dxt0) + (dvy3 * dyt0) + (xtruZ * dzt0);
99

    
100
        coord_out.setLocation(dxt, dyt, dzt);
101

    
102
        //coord_out.z = dzt;
103
        dxt0 = 0;
104
        dyt0 = 0;
105
        dzt0 = 0;
106

    
107
        return coord_out;
108
    }
109
    
110
    /**
111
     * Devuelve el coseno de un ?ngulo introducido en grados sexagesimales.
112
     * @param alfa, ?ngulo.
113
     * @return double, valor del coseno.
114
     */
115
    public static double cosDeg(double alfa) {
116
        final double toRad = Math.PI / (double) 180.0;
117

    
118
        return Math.cos(alfa * toRad);
119
    }
120
    
121
    /**
122
     * Devuelve el seno de un ?ngulo introducido en grados sexagesimales.
123
     * @param alfa, ?ngulo.
124
     * @return double, valor del seno.
125
     */
126
    public static double sinDeg(double alfa) {
127
        final double toRad = Math.PI / (double) 180.0;
128

    
129
        return Math.sin(alfa * toRad);
130
    }
131
}