Statistics
| Revision:

root / trunk / libraries / libCq_CMS_praster / src / org / cresques / px / dxf / DxfCalXtru.java @ 8026

History | View | Annotate | Download (3.85 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.Point3D;
27

    
28
import java.lang.Math;
29

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

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

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

    
65
        dxt0 = coord_in.getX();
66
        dyt0 = coord_in.getY();
67
        dzt0 = coord_in.getZ();
68

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

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

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

    
92
        dmod = Math.sqrt((dvy1 * dvy1) + (dvy2 * dvy2) + (dvy3 * dvy3));
93

    
94
        dvy1 = dvy1 / dmod;
95
        dvy2 = dvy2 / dmod;
96
        dvy3 = dvy3 / dmod;
97

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

    
102
        coord_out.setLocation(dxt, dyt, dzt);
103

    
104
        //coord_out.z = dzt;
105
        dxt0 = 0;
106
        dyt0 = 0;
107
        dzt0 = 0;
108

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

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

    
131
        return Math.sin(alfa * toRad);
132
    }
133
}