root / trunk / libraries / lib3DMap / src / com / iver / ai2 / gvsig3d / utils / UtilCoord.java @ 20891
History | View | Annotate | Download (4.3 KB)
1 |
package com.iver.ai2.gvsig3d.utils; |
---|---|
2 |
|
3 |
import java.awt.geom.Rectangle2D; |
4 |
|
5 |
import org.gvsig.osgvp.Vec3; |
6 |
import org.gvsig.osgvp.viewer.Camera; |
7 |
|
8 |
public class UtilCoord { |
9 |
static String mensaje; |
10 |
|
11 |
private static double radio; |
12 |
|
13 |
static {
|
14 |
radio = 6378137.0;
|
15 |
} |
16 |
|
17 |
/**
|
18 |
* Method to transform geodesic coordinates to geometrical coordinates
|
19 |
*
|
20 |
* @param r
|
21 |
* radio
|
22 |
* @param alpha
|
23 |
* angle in degrees
|
24 |
* @param beta
|
25 |
* angle in degrees
|
26 |
* @return a vector with X,Y and Z values
|
27 |
*/
|
28 |
public static Vec3 GeoToCarte(double r, double alpha, double beta) { |
29 |
return GeoToCarte(new Vec3(r, alpha, beta)); |
30 |
} |
31 |
|
32 |
/**
|
33 |
* Method to transform geodesic coordinates to geometrical coordinates
|
34 |
*
|
35 |
* @param coord
|
36 |
* vertor with radio, alpha and beta values in this order
|
37 |
* @return a vector with X,Y and Z values in this order
|
38 |
*/
|
39 |
public static Vec3 GeoToCarte(Vec3 coord) { |
40 |
Vec3 result = new Vec3();
|
41 |
|
42 |
double h = coord.x();
|
43 |
double alphaRad = radianes(coord.y());
|
44 |
double betaRad = radianes(coord.z());
|
45 |
|
46 |
double sinA = Math.sin(alphaRad); |
47 |
double cosA = Math.cos(alphaRad); |
48 |
double sinB = Math.sin(betaRad); |
49 |
double cosB = Math.cos(betaRad); |
50 |
|
51 |
// Calculate the X value
|
52 |
result.setX(h * cosA * cosB); |
53 |
|
54 |
// Calculate the Y value
|
55 |
result.setY(h * sinA * cosB); |
56 |
|
57 |
// Calculate the Z value
|
58 |
result.setZ(h * sinB); |
59 |
|
60 |
return result;
|
61 |
} |
62 |
|
63 |
/**
|
64 |
* Method to transform geometrical coordinates to geodesic coordinates
|
65 |
*
|
66 |
* @param x
|
67 |
* value
|
68 |
* @param y
|
69 |
* value
|
70 |
* @param z
|
71 |
* value
|
72 |
* @return a vector with radio, alpha and beta values in this order
|
73 |
*/
|
74 |
public static Vec3 CarteToGeo(double x, double y, double z) { |
75 |
return CarteToGeo(new Vec3(x, y, z)); |
76 |
} |
77 |
|
78 |
/**
|
79 |
* Method to transform geometrical coordinates to geodesic coordinates
|
80 |
*
|
81 |
* @param coord
|
82 |
* vector with X,Y and Z values in this order
|
83 |
* @return vertor with radio, alpha and beta values in this order
|
84 |
*/
|
85 |
public static Vec3 CarteToGeo(Vec3 coord) { |
86 |
Vec3 result = new Vec3();
|
87 |
|
88 |
// Caculate the radio value
|
89 |
double modx = coord.x() * coord.x();
|
90 |
double mody = coord.y() * coord.y();
|
91 |
double modz = coord.z() * coord.z();
|
92 |
|
93 |
result.setX(Math.sqrt(modx + mody + modz));
|
94 |
|
95 |
// Calculate the alpha angle
|
96 |
double sqrt = Math.sqrt(modx + mody); |
97 |
double alpha = Math.atan(coord.z() / sqrt); |
98 |
result.setY(degrees(alpha)); |
99 |
|
100 |
// Calculate the beta angle
|
101 |
double beta = degrees(Math.atan2(coord.y(), coord.x())); |
102 |
result.setZ(beta); |
103 |
|
104 |
return result;
|
105 |
} |
106 |
|
107 |
/**
|
108 |
* Method to transform degrees to radianes
|
109 |
*
|
110 |
* @param degrees
|
111 |
* value
|
112 |
* @return radianes value
|
113 |
*/
|
114 |
public static double radianes(double degrees) { |
115 |
return ((degrees * Math.PI) / 180); |
116 |
} |
117 |
|
118 |
public static double degrees(double rad) { |
119 |
return ((rad * 180) / Math.PI); |
120 |
} |
121 |
|
122 |
public static void imprimeCamara(Camera camera) { |
123 |
Vec3 c, e, u; |
124 |
c = camera.getCenter(); |
125 |
e = camera.getEye(); |
126 |
u = camera.getUp(); |
127 |
|
128 |
System.out.println("********* POSICION DE LA CAMARA *****************"); |
129 |
System.out.println("CENTER : X " + c.x() + " Y " + c.y() + "Z " + c.z()); |
130 |
System.out.println("EYE : X " + e.x() + " Y " + e.y() + "Z " + e.z()); |
131 |
System.out.println("UP : X " + u.x() + " Y " + u.y() + "Z " + u.z()); |
132 |
System.out.println("*************************************************"); |
133 |
} |
134 |
|
135 |
public static Rectangle2D getExtendGeo(double longi, double lati, double size,double radius){ |
136 |
|
137 |
double with = size / radius;
|
138 |
double heigth = size / ( radius * Math.cos(lati)); |
139 |
Rectangle2D extend = new Rectangle2D.Double(longi,lati,with,heigth); |
140 |
|
141 |
return extend;
|
142 |
} |
143 |
|
144 |
public static Vec3 getDegreesHMS(double num) { |
145 |
// transform degrees in sexagesinal format
|
146 |
int grados = (int) num; |
147 |
double resG = num - grados;
|
148 |
int minutos = (int) (resG * 60); |
149 |
double minutosD = (resG * 60); |
150 |
double resM = minutosD - minutos;
|
151 |
int segundos = (int) (resM * 60); |
152 |
String cadG = ""; |
153 |
if (grados < 10) |
154 |
cadG = cadG + "0";
|
155 |
cadG = cadG + grados; |
156 |
|
157 |
String cadM = ""; |
158 |
if (minutos < 10) |
159 |
cadM = cadM + "0";
|
160 |
cadM = cadM + minutos; |
161 |
|
162 |
String cadS = ""; |
163 |
if (segundos < 10) |
164 |
cadS = cadS + "0";
|
165 |
cadS = cadS + segundos; |
166 |
|
167 |
|
168 |
return (new Vec3(grados,minutos,segundos)); |
169 |
} |
170 |
|
171 |
} |