Statistics
| Revision:

svn-gvsig-desktop / branches / CqCMSDvp / libraries / libCq CMS for java.old / src / org / cresques / px / dxf / DxfCalXtru.java @ 2312

History | View | Annotate | Download (3.02 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 java.lang.Math;
27
import org.cresques.geo.Point3D;
28

    
29
public class DxfCalXtru {
30
        public static Point3D CalculateXtru(Point3D coord_in, Point3D xtru) {
31
                Point3D coord_out = new Point3D();
32
                
33
        double dxt0 = 0D, dyt0 = 0D, dzt0 = 0D;
34
        double dvx1, dvx2, dvx3;
35
        double dvy1, dvy2, dvy3;
36
        double dmod, dxt, dyt, dzt;
37
        
38
        double aux = 1D/64D; //LWS
39
        double aux1 = Math.abs(xtru.getX());
40
        double aux2 = Math.abs(xtru.getY());
41
        
42
        dxt0 = coord_in.getX();
43
        dyt0 = coord_in.getY();
44
        dzt0 = coord_in.getZ();
45
        
46
        double xtruX, xtruY, xtruZ;
47
        xtruX = xtru.getX();
48
        xtruY = xtru.getY();
49
        xtruZ = xtru.getZ();
50

    
51
        if ((aux1 < aux) && (aux2 < aux)) {
52
            dmod = Math.sqrt(xtruZ*xtruZ + xtruX*xtruX);
53
            dvx1 = xtruZ / dmod;
54
            dvx2 = 0;
55
            dvx3 = -xtruX / dmod;
56
        } else {
57
            dmod = Math.sqrt(xtruY*xtruY + xtruX*xtruX);
58
            dvx1 = -xtruY / dmod;
59
            dvx2 = xtruX / dmod;
60
            dvx3 = 0;
61
        }
62

    
63
        dvy1 = xtruY*dvx3 - xtruZ*dvx2;
64
        dvy2 = xtruZ*dvx1 - xtruX*dvx3;
65
        dvy3 = xtruX*dvx2 - xtruY*dvx1;
66

    
67
        dmod = Math.sqrt(dvy1*dvy1 + dvy2*dvy2 + dvy3*dvy3);
68

    
69
        dvy1 = dvy1 / dmod;
70
        dvy2 = dvy2 / dmod;
71
        dvy3 = dvy3 / dmod;
72

    
73
        dxt = dvx1*dxt0 + dvy1*dyt0 + xtruX*dzt0;
74
        dyt = dvx2*dxt0 + dvy2*dyt0 + xtruY*dzt0;
75
        dzt = dvx3*dxt0 + dvy3*dyt0 + xtruZ*dzt0;
76

    
77
        coord_out.setLocation(dxt, dyt, dzt);
78
        //coord_out.z = dzt;
79

    
80
        dxt0 = 0;
81
        dyt0 = 0;
82
        dzt0 = 0;
83
        
84
                return coord_out;
85
        }
86
        
87
    public static double cosDeg(double alfa) {
88
            final double toRad = Math.PI/(double)180.0;
89
            return Math.cos(alfa*toRad);
90
    }
91

    
92
    public static double sinDeg(double alfa) {
93
            final double toRad = Math.PI/(double)180.0;
94
            return Math.sin(alfa*toRad);
95
    }
96
    
97
    public static void CalculateArc(double[] dat, double r, double angulo) {
98
            dat[1] = dat[1] + r * Math.sin(angulo*Math.PI/(double)180.0);
99
            dat[0] = dat[0] + r * Math.cos(angulo*Math.PI/(double)180.0);
100
    }
101
    
102
}