svn-gvsig-desktop / tags / v2_0_0_Build_2057 / libraries / libFMap_geometries / src / org / gvsig / fmap / geom / util / UtilFunctions.java @ 39171
History | View | Annotate | Download (18.3 KB)
1 |
/*
|
---|---|
2 |
* Created on 10-feb-2005
|
3 |
*
|
4 |
* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana
|
5 |
*
|
6 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
7 |
*
|
8 |
* This program is free software; you can redistribute it and/or
|
9 |
* modify it under the terms of the GNU General Public License
|
10 |
* as published by the Free Software Foundation; either version 2
|
11 |
* of the License, or (at your option) any later version.
|
12 |
*
|
13 |
* This program is distributed in the hope that it will be useful,
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16 |
* GNU General Public License for more details.
|
17 |
*
|
18 |
* You should have received a copy of the GNU General Public License
|
19 |
* along with this program; if not, write to the Free Software
|
20 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
21 |
*
|
22 |
* For more information, contact:
|
23 |
*
|
24 |
* Generalitat Valenciana
|
25 |
* Conselleria d'Infraestructures i Transport
|
26 |
* Av. Blasco Ib��ez, 50
|
27 |
* 46010 VALENCIA
|
28 |
* SPAIN
|
29 |
*
|
30 |
* +34 963862235
|
31 |
* gvsig@gva.es
|
32 |
* www.gvsig.gva.es
|
33 |
*
|
34 |
* or
|
35 |
*
|
36 |
* IVER T.I. S.A
|
37 |
* Salamanca 50
|
38 |
* 46005 Valencia
|
39 |
* Spain
|
40 |
*
|
41 |
* +34 963163400
|
42 |
* dac@iver.es
|
43 |
*/
|
44 |
package org.gvsig.fmap.geom.util; |
45 |
|
46 |
import java.awt.geom.AffineTransform; |
47 |
import java.awt.geom.Arc2D; |
48 |
import java.awt.geom.Line2D; |
49 |
import java.awt.geom.Point2D; |
50 |
import java.awt.geom.Rectangle2D; |
51 |
|
52 |
import org.gvsig.fmap.geom.Geometry; |
53 |
import org.gvsig.fmap.geom.GeometryManager; |
54 |
import org.slf4j.Logger; |
55 |
import org.slf4j.LoggerFactory; |
56 |
|
57 |
import com.vividsolutions.jts.algorithm.RobustCGAlgorithms; |
58 |
import com.vividsolutions.jts.geom.Coordinate; |
59 |
|
60 |
/**
|
61 |
* @author FJP
|
62 |
*
|
63 |
* TODO To change the template for this generated type comment go to
|
64 |
* Window - Preferences - Java - Code Generation - Code and Comments
|
65 |
* @deprecated to be removed or moved from API to implementation in gvSIG 2.1.0
|
66 |
*/
|
67 |
public class UtilFunctions { |
68 |
private static final Logger logger = LoggerFactory.getLogger(GeometryManager.class); |
69 |
|
70 |
static public Arc2D createCircle(Point2D p1, Point2D p2, Point2D p3) //, Graphics g) |
71 |
{ |
72 |
double xC, yC, w, h;
|
73 |
|
74 |
// Calculamos 2 secantes, tiramos perpendiculares por sus puntos
|
75 |
// medios y obtenemos el centro. Luego calculamos el radio.
|
76 |
// Puntos medios de los segmentos.
|
77 |
double xm1, ym1, xm2, ym2;
|
78 |
xm1 = (p1.getX() + p2.getX())/ 2.0;
|
79 |
ym1 = (p1.getY() + p2.getY())/ 2.0;
|
80 |
xm2 = (p2.getX() + p3.getX())/ 2.0;
|
81 |
ym2 = (p2.getY() + p3.getY())/ 2.0;
|
82 |
|
83 |
/* g.setColor(Color.GRAY);
|
84 |
g.draw3DRect((int)xm1, (int) ym1, 1, 1, true);
|
85 |
g.draw3DRect((int)xm2, (int) ym2, 1, 1, true); */
|
86 |
// Pendientes de las perpendiculares y constantes
|
87 |
double mP1=0, mP2=0, A1, A2; |
88 |
boolean bPerp1 = false; |
89 |
//boolean bPerp2 = false;
|
90 |
if (p2.getY() - p1.getY() == 0) |
91 |
{ |
92 |
A1 = ym1; |
93 |
bPerp1 = true;
|
94 |
} |
95 |
else
|
96 |
{ |
97 |
mP1 = (p2.getX() - p1.getX()) /(p1.getY() - p2.getY()); |
98 |
A1 = ym1 - xm1 * mP1; |
99 |
} |
100 |
if (p2.getY() - p3.getY() == 0) |
101 |
{ |
102 |
A2 = ym2; |
103 |
//bPerp2 = true;
|
104 |
} |
105 |
else
|
106 |
{ |
107 |
mP2 = (p3.getX() - p2.getX()) /(p2.getY() - p3.getY()); |
108 |
A2 = ym2 - xm2 * mP2; |
109 |
} |
110 |
if (mP2 == mP1)
|
111 |
{ |
112 |
return null; // Error, 3 puntos alineados. No puede pasar un arco |
113 |
} |
114 |
else
|
115 |
{ |
116 |
xC = (A2 - A1)/(mP1-mP2); |
117 |
if (!bPerp1) {
|
118 |
yC = xC * mP1 + A1; |
119 |
} else {
|
120 |
yC = xC * mP2 + A2; |
121 |
} |
122 |
} |
123 |
double Radio = p1.distance(xC, yC);
|
124 |
double xR = xC - Radio ;
|
125 |
double yR = yC - Radio ;
|
126 |
w = 2.0* Radio;
|
127 |
h = w; |
128 |
Rectangle2D.Double rBounds = new Rectangle2D.Double(xR,yR, w,h); |
129 |
Arc2D.Double resul = new Arc2D.Double(rBounds, 0.0, 360.0, Arc2D.OPEN); |
130 |
/* g.setColor(Color.RED);
|
131 |
((Graphics2D) g).draw(resul);
|
132 |
g.setColor(Color.BLUE);
|
133 |
((Graphics2D) g).draw(rBounds);
|
134 |
g.draw3DRect((int)p1.getX(), (int) p1.getY(), 1, 1, true);
|
135 |
g.draw3DRect((int)p2.getX(), (int) p2.getY(), 2, 2, true);
|
136 |
g.draw3DRect((int)p3.getX(), (int) p3.getY(), 1, 1, true);
|
137 |
g.drawString("1", (int) p1.getX(), (int) p1.getY());
|
138 |
g.drawString("2", (int) p2.getX(), (int) p2.getY());
|
139 |
g.drawString("3", (int) p3.getX(), (int) p3.getY());
|
140 |
g.drawString("C", (int) xC, (int) yC);
|
141 |
g.draw3DRect((int)xC, (int) yC, 2, 2, true); */
|
142 |
|
143 |
return resul;
|
144 |
} |
145 |
/**
|
146 |
* Obtiene un par de puntos que definen la recta perpendicular a p1-p2 que
|
147 |
* pasa por el punto perp
|
148 |
*
|
149 |
* @param p1 punto de la recta p1-p2
|
150 |
* @param p2 punto de la recta p1-p2
|
151 |
* @param perp Punto por el que pasa la recta perpendicular, debe ser
|
152 |
* distinto a p2
|
153 |
*
|
154 |
* @return Array con dos puntos que definen la recta resultante
|
155 |
* @deprecated
|
156 |
* use the perpendicular operation
|
157 |
*/
|
158 |
public static Point2D[] getPerpendicular(Point2D p1, Point2D p2, |
159 |
Point2D perp) {
|
160 |
if ((p2.getY() - p1.getY()) == 0) { |
161 |
return new Point2D[] { |
162 |
new Point2D.Double(perp.getX(), 0), |
163 |
new Point2D.Double(perp.getX(), 1) |
164 |
}; |
165 |
} |
166 |
|
167 |
//Pendiente de la recta perpendicular
|
168 |
double m = (p1.getX() - p2.getX()) / (p2.getY() - p1.getY());
|
169 |
|
170 |
//b de la funcion de la recta perpendicular
|
171 |
double b = perp.getY() - (m * perp.getX());
|
172 |
|
173 |
//Obtenemos un par de puntos
|
174 |
Point2D[] res = new Point2D[2]; |
175 |
|
176 |
res[0] = new Point2D.Double(0, (m * 0) + b); |
177 |
res[1] = new Point2D.Double(1000, (m * 1000) + b); |
178 |
|
179 |
return res;
|
180 |
} |
181 |
public static Point2D[] getParallel(Point2D p1,Point2D p2,double distance) { |
182 |
Point2D[] pParallel=new Point2D[2]; |
183 |
pParallel[0]=getPerpendicularPoint(p1,p2,p1,distance);
|
184 |
pParallel[1]=getPerpendicularPoint(p1,p2,p2,distance);
|
185 |
return pParallel;
|
186 |
} |
187 |
|
188 |
/**
|
189 |
* Obtiene el punto que se encuentra a una distancia 'dist' de la recta
|
190 |
* p1-p2 y se encuentra en la recta perpendicular que pasa por perpPoint
|
191 |
*
|
192 |
* @param p1 Punto de la recta p1-p2
|
193 |
* @param p2 Punto de la recta p1-p2
|
194 |
* @param perpPoint Punto de la recta perpendicular
|
195 |
* @param dist Distancia del punto que se quiere obtener a la recta p1-p2
|
196 |
*
|
197 |
* @return DOCUMENT ME!
|
198 |
* @deprecated
|
199 |
* Use the perpendicularPoint operation
|
200 |
*/
|
201 |
public static Point2D getPerpendicularPoint(Point2D p1, Point2D p2, |
202 |
Point2D perpPoint, double dist) { |
203 |
Point2D[] p = getPerpendicular(p1, p2, perpPoint); |
204 |
Point2D unit = getUnitVector(p[0], p[1]); |
205 |
|
206 |
return new Point2D.Double(perpPoint.getX() + (unit.getX() * dist), |
207 |
perpPoint.getY() + (unit.getY() * dist)); |
208 |
} |
209 |
|
210 |
/**
|
211 |
* Devuelve un vector unitario en forma de punto a partir de dos puntos.
|
212 |
*
|
213 |
* @param p1 punto origen.
|
214 |
* @param p2 punto destino.
|
215 |
*
|
216 |
* @return vector unitario.
|
217 |
* @deprecated
|
218 |
* use the UnitVector operation
|
219 |
*/
|
220 |
public static Point2D getUnitVector(Point2D p1, Point2D p2) { |
221 |
Point2D paux = new Point2D.Double(p2.getX() - p1.getX(), |
222 |
p2.getY() - p1.getY()); |
223 |
double v = Math.sqrt(Math.pow(paux.getX(), 2d) + |
224 |
Math.pow(paux.getY(), 2d)); |
225 |
paux = new Point2D.Double(paux.getX() / v, paux.getY() / v); |
226 |
|
227 |
return paux;
|
228 |
} |
229 |
/**
|
230 |
* Obtiene el centro del c�rculo que pasa por los tres puntos que se pasan
|
231 |
* como par�metro
|
232 |
*
|
233 |
* @param p1 primer punto del c�rculo cuyo centro se quiere obtener
|
234 |
* @param p2 segundo punto del c�rculo cuyo centro se quiere obtener
|
235 |
* @param p3 tercer punto del c�rculo cuyo centro se quiere obtener
|
236 |
*
|
237 |
* @return Devuelve null si los puntos est�n alineados o no son 3 puntos
|
238 |
* distintos
|
239 |
*/
|
240 |
public static Point2D getCenter(Point2D p1, Point2D p2, Point2D p3) { |
241 |
if (p1.equals(p2) || p2.equals(p3) || p1.equals(p3)) {
|
242 |
return null; |
243 |
} |
244 |
|
245 |
Point2D[] perp1 = getPerpendicular(p1, p2, |
246 |
new Point2D.Double((p1.getX() + p2.getX()) / 2, |
247 |
(p1.getY() + p2.getY()) / 2));
|
248 |
Point2D[] perp2 = getPerpendicular(p2, p3, |
249 |
new Point2D.Double((p2.getX() + p3.getX()) / 2, |
250 |
(p2.getY() + p3.getY()) / 2));
|
251 |
|
252 |
return getIntersection(perp1[0], perp1[1], perp2[0], perp2[1]); |
253 |
} |
254 |
|
255 |
|
256 |
/**
|
257 |
* Devuelve el punto de la intersecci�n entre las lineas p1-p2 y p3-p4.
|
258 |
*
|
259 |
* @param p1 punto de la recta p1-p2
|
260 |
* @param p2 punto de la recta p1-p2
|
261 |
* @param p3 punto de la recta p3-p4
|
262 |
* @param p4 punto de la recta p3-p4
|
263 |
*
|
264 |
* @return DOCUMENT ME!
|
265 |
*
|
266 |
* @throws RuntimeException DOCUMENT ME!
|
267 |
*/
|
268 |
public static Point2D getIntersection(Point2D p1, Point2D p2, Point2D p3, |
269 |
Point2D p4) {
|
270 |
double m1 = Double.POSITIVE_INFINITY; |
271 |
|
272 |
if ((p2.getX() - p1.getX()) != 0) { |
273 |
m1 = (p2.getY() - p1.getY()) / (p2.getX() - p1.getX()); |
274 |
} |
275 |
|
276 |
double m2 = Double.POSITIVE_INFINITY; |
277 |
|
278 |
if ((p4.getX() - p3.getX()) != 0) { |
279 |
m2 = (p4.getY() - p3.getY()) / (p4.getX() - p3.getX()); |
280 |
} |
281 |
|
282 |
if ((m1 == Double.POSITIVE_INFINITY) && |
283 |
(m2 == Double.POSITIVE_INFINITY)) {
|
284 |
return null; |
285 |
} |
286 |
|
287 |
double b1 = p2.getY() - (m1 * p2.getX());
|
288 |
|
289 |
double b2 = p4.getY() - (m2 * p4.getX());
|
290 |
|
291 |
if ((m1 != Double.POSITIVE_INFINITY) && |
292 |
(m2 != Double.POSITIVE_INFINITY)) {
|
293 |
if (m1 == m2) {
|
294 |
return null; |
295 |
} |
296 |
|
297 |
double x = (b2 - b1) / (m1 - m2);
|
298 |
|
299 |
return new Point2D.Double(x, (m1 * x) + b1); |
300 |
} else if (m1 == Double.POSITIVE_INFINITY) { |
301 |
double x = p1.getX();
|
302 |
|
303 |
return new Point2D.Double(x, (m2 * x) + b2); |
304 |
} else if (m2 == Double.POSITIVE_INFINITY) { |
305 |
double x = p3.getX();
|
306 |
|
307 |
return new Point2D.Double(x, (m1 * x) + b1); |
308 |
} |
309 |
|
310 |
//no llega nunca
|
311 |
throw new RuntimeException("BUG!"); |
312 |
} |
313 |
/**
|
314 |
* Obtiene el �ngulo del vector que se pasa como par�metro con el vector
|
315 |
* horizontal de izquierda a derecha
|
316 |
*
|
317 |
* @param start punto origen del vector
|
318 |
* @param end punto destino del vector
|
319 |
*
|
320 |
* @return angulo en radianes
|
321 |
*/
|
322 |
public static double getAngle(Point2D start, Point2D end) { |
323 |
double angle = Math.acos((end.getX() - start.getX()) / start.distance( |
324 |
end)); |
325 |
|
326 |
if (start.getY() > end.getY()) {
|
327 |
angle = -angle; |
328 |
} |
329 |
|
330 |
if (angle < 0) { |
331 |
angle += (2 * Math.PI); |
332 |
} |
333 |
|
334 |
return angle;
|
335 |
} |
336 |
/**
|
337 |
* Devuelve la distancia desde angle1 a angle2. Angulo en radianes de
|
338 |
* diferencia entre angle1 y angle2 en sentido antihorario
|
339 |
*
|
340 |
* @param angle1 angulo en radianes. Debe ser positivo y no dar ninguna
|
341 |
* vuelta a la circunferencia
|
342 |
* @param angle2 angulo en radianes. Debe ser positivo y no dar ninguna
|
343 |
* vuelta a la circunferencia
|
344 |
*
|
345 |
* @return distancia entre los �ngulos
|
346 |
*/
|
347 |
public static double angleDistance(double angle1, double angle2) { |
348 |
if (angle1 < angle2) {
|
349 |
return angle2 - angle1;
|
350 |
} else {
|
351 |
return ((Math.PI * 2) - angle1) + angle2; |
352 |
} |
353 |
} |
354 |
/**
|
355 |
* Devuelve el punto de la recta que viene dada por los puntos p1 y p2 a
|
356 |
* una distancia radio de p1.
|
357 |
*
|
358 |
* @param p1 DOCUMENT ME!
|
359 |
* @param p2 DOCUMENT ME!
|
360 |
* @param radio DOCUMENT ME!
|
361 |
*
|
362 |
* @return DOCUMENT ME!
|
363 |
*/
|
364 |
public static Point2D getPoint(Point2D p1, Point2D p2, double radio) { |
365 |
Point2D paux = new Point2D.Double(p2.getX() - p1.getX(), |
366 |
p2.getY() - p1.getY()); |
367 |
double v = Math.sqrt(Math.pow(paux.getX(), 2d) + |
368 |
Math.pow(paux.getY(), 2d)); |
369 |
paux = new Point2D.Double(paux.getX() / v, paux.getY() / v); |
370 |
|
371 |
Point2D aux1 = new Point2D.Double(p1.getX() + (radio * paux.getX()), |
372 |
p1.getY() + (radio * paux.getY())); |
373 |
|
374 |
return aux1;
|
375 |
} |
376 |
/**
|
377 |
* Devuelve la menor distancia desde angle1 a angle2.
|
378 |
*
|
379 |
* @param angle1 angulo en radianes. Debe ser positivo y no dar ninguna
|
380 |
* vuelta a la circunferencia
|
381 |
* @param angle2 angulo en radianes. Debe ser positivo y no dar ninguna
|
382 |
* vuelta a la circunferencia
|
383 |
*
|
384 |
* @return distancia entre los �ngulos
|
385 |
*/
|
386 |
public static double absoluteAngleDistance(double angle1, double angle2) { |
387 |
double d = Math.abs(angle1 - angle2); |
388 |
|
389 |
if (d < Math.PI) { |
390 |
return d;
|
391 |
} else {
|
392 |
if (angle1 < angle2) {
|
393 |
angle2 -= (Math.PI * 2); |
394 |
} else {
|
395 |
angle1 -= (Math.PI * 2); |
396 |
} |
397 |
|
398 |
return Math.abs(angle1 - angle2); |
399 |
} |
400 |
} |
401 |
/**
|
402 |
* Obtiene un arco a partir de 3 puntos. Devuelve null si no se puede crear
|
403 |
* el arco porque los puntos est�n alineados o los 3 puntos no son
|
404 |
* distintos
|
405 |
*
|
406 |
* @param p1
|
407 |
* @param p2
|
408 |
* @param p3
|
409 |
*
|
410 |
* @return Arco
|
411 |
*/
|
412 |
public static Arc2D createArc(Point2D p1, Point2D p2, Point2D p3) { |
413 |
Point2D center = getCenter(p1, p2, p3);
|
414 |
|
415 |
double angle1;
|
416 |
double angle2;
|
417 |
double extent;
|
418 |
|
419 |
if (center == null) { |
420 |
if (p1.equals(p3) && !p2.equals(p1)) {
|
421 |
//Si los puntos p1 y p3 son los mismos (pero el p2 no),
|
422 |
//consideramos que el arco es una circunferencia completa
|
423 |
center = new Point2D.Double((p1.getX() + p2.getX()) / 2, |
424 |
(p1.getY() + p2.getY()) / 2);
|
425 |
angle1 = getAngle(center, p1); |
426 |
extent = Math.PI*2; |
427 |
} else {
|
428 |
//en cualquier otro caso, no podemos crear el arco.
|
429 |
return null; |
430 |
} |
431 |
} else {
|
432 |
|
433 |
angle1 = getAngle(center, p1); |
434 |
angle2 = getAngle(center, p3); |
435 |
extent = angleDistance(angle1, angle2); |
436 |
|
437 |
Coordinate[] coords = new Coordinate[4]; |
438 |
coords[0] = new Coordinate(p1.getX(), p1.getY()); |
439 |
coords[1] = new Coordinate(p2.getX(), p2.getY()); |
440 |
coords[2] = new Coordinate(p3.getX(), p3.getY()); |
441 |
coords[3] = new Coordinate(p1.getX(), p1.getY()); |
442 |
|
443 |
if (!RobustCGAlgorithms.isCCW(coords)) {
|
444 |
extent = (Math.PI * 2) - extent; |
445 |
} else {
|
446 |
extent = -extent; |
447 |
} |
448 |
} |
449 |
//System.err.println("angle1:" + angle1);
|
450 |
//System.err.println("angle2:" + getAngle(center, p2));
|
451 |
//System.err.println("angle3:" + angle2);
|
452 |
//System.err.println("extent:" + extent);
|
453 |
double Radio = p1.distance(center);
|
454 |
double xR = center.getX() - Radio;
|
455 |
double yR = center.getY() - Radio;
|
456 |
double w = 2.0 * Radio; |
457 |
double h = w;
|
458 |
|
459 |
Rectangle2D.Double rBounds = new Rectangle2D.Double(xR, yR, w, h); |
460 |
Arc2D.Double resul = new Arc2D.Double(rBounds, |
461 |
Math.toDegrees((Math.PI * 2) - angle1), Math.toDegrees(extent), |
462 |
Arc2D.OPEN);
|
463 |
|
464 |
return resul;
|
465 |
} |
466 |
|
467 |
/**
|
468 |
* Obtiene un arco a partir del centro, radio, angulo inicial y extension del angulo.
|
469 |
* Devuelve null si no lo puede crear.
|
470 |
*
|
471 |
* @param center
|
472 |
* @param radius
|
473 |
* @param angSt en radianes
|
474 |
* @param angExt en radianes
|
475 |
*
|
476 |
* @return Arco
|
477 |
*/
|
478 |
public static Arc2D createArc(Point2D center, double radius, double angSt, double angExt) { |
479 |
double xR = center.getX() - radius;
|
480 |
double yR = center.getY() - radius;
|
481 |
double w = 2.0 * radius; |
482 |
double h = w;
|
483 |
|
484 |
Rectangle2D.Double rBounds = new Rectangle2D.Double(xR, yR, w, h); |
485 |
Arc2D.Double resul = new Arc2D.Double(rBounds, |
486 |
Math.toDegrees((Math.PI * 2) - angSt), Math.toDegrees(angExt), |
487 |
Arc2D.OPEN);
|
488 |
|
489 |
return resul;
|
490 |
} |
491 |
|
492 |
/**
|
493 |
* Obtiene un arco a partir del
|
494 |
* centro del arco y punto inicio y punto final
|
495 |
* Suponemos un Arco definicio CCW (CounterClockWise)
|
496 |
* @param center
|
497 |
* @param init
|
498 |
* @param end
|
499 |
*
|
500 |
* @return Arco
|
501 |
*/
|
502 |
public static Arc2D createArc2points(Point2D center, Point2D init, Point2D end) { |
503 |
|
504 |
double angle1 = getAngle(center, init);
|
505 |
double angle2 = getAngle(center, end);
|
506 |
double extent = angleDistance(angle1, angle2);
|
507 |
|
508 |
extent = -extent; // CCW
|
509 |
|
510 |
//System.err.println("angle1:" + angle1);
|
511 |
//System.err.println("angle2:" + getAngle(center, p2));
|
512 |
//System.err.println("angle3:" + angle2);
|
513 |
//System.err.println("extent:" + extent);
|
514 |
double Radio = init.distance(center);
|
515 |
double xR = center.getX() - Radio;
|
516 |
double yR = center.getY() - Radio;
|
517 |
double w = 2.0 * Radio; |
518 |
double h = w;
|
519 |
|
520 |
Rectangle2D.Double rBounds = new Rectangle2D.Double(xR, yR, w, h); |
521 |
Arc2D.Double resul = new Arc2D.Double(rBounds, |
522 |
Math.toDegrees((Math.PI * 2) - angle1), Math.toDegrees(extent), |
523 |
Arc2D.OPEN);
|
524 |
|
525 |
return resul;
|
526 |
} |
527 |
|
528 |
/**
|
529 |
* Devuelve el punto a una distancia radio del punto p1 y aplicandole un �ngulo an.
|
530 |
* una distancia radio de p1.
|
531 |
*
|
532 |
* @param p1 DOCUMENT ME!
|
533 |
* @param p2 DOCUMENT ME!
|
534 |
* @param radio DOCUMENT ME!
|
535 |
*
|
536 |
* @return DOCUMENT ME!
|
537 |
*/
|
538 |
public static Point2D getPoint(Point2D p1, double an, double radio) { |
539 |
double x=(radio*Math.cos(an))+p1.getX(); |
540 |
double y=(radio*Math.sin(an))+p1.getY(); |
541 |
|
542 |
Point2D p=new Point2D.Double(x,y); |
543 |
|
544 |
return p;
|
545 |
} |
546 |
|
547 |
/**
|
548 |
* Obtiene una linea a partir de dos puntos.
|
549 |
* Devuelve null si no lo puede crear.
|
550 |
*
|
551 |
* @param start
|
552 |
* @param end
|
553 |
*
|
554 |
* @return Linea
|
555 |
*/
|
556 |
public static Line2D createLine(Point2D start, Point2D end) { |
557 |
return new Line2D.Double(start, end); |
558 |
|
559 |
} |
560 |
|
561 |
|
562 |
/**
|
563 |
* DOCUMENT ME!
|
564 |
*
|
565 |
* @param antp DOCUMENT ME!
|
566 |
* @param lastp DOCUMENT ME!
|
567 |
* @param interp DOCUMENT ME!
|
568 |
* @param point DOCUMENT ME!
|
569 |
*
|
570 |
* @return DOCUMENT ME!
|
571 |
*/
|
572 |
public static boolean isLowAngle(Point2D antp, Point2D lastp, |
573 |
Point2D interp, Point2D point) { |
574 |
///double ob=lastp.distance(point);
|
575 |
///Point2D[] aux=getPerpendicular(lastp,interp,point);
|
576 |
///Point2D intersect=getIntersection(aux[0],aux[1],lastp,interp);
|
577 |
///double pb=intersect.distance(point);
|
578 |
///double a=Math.asin(pb/ob);
|
579 |
Coordinate[] coords = new Coordinate[4]; |
580 |
coords[0] = new Coordinate(lastp.getX(), lastp.getY()); |
581 |
coords[1] = new Coordinate(interp.getX(), interp.getY()); |
582 |
coords[2] = new Coordinate(point.getX(), point.getY()); |
583 |
coords[3] = new Coordinate(lastp.getX(), lastp.getY()); |
584 |
|
585 |
try {
|
586 |
double angle1 = getAngle(antp, lastp);
|
587 |
// System.out.println("angle1= " + angle1);
|
588 |
|
589 |
double angle2 = getAngle(lastp, point);
|
590 |
// System.out.println("angle2= " + angle2);
|
591 |
|
592 |
/*if (lastp.getX()<antp.getX()){
|
593 |
System.out.println("angleDiff 2 1= "+angleDistance(angle2,angle1));
|
594 |
System.out.println("angleDiff 1 2= "+angleDistance(angle1,angle2));
|
595 |
if (angleDistance(angle2,angle1)>Math.PI){
|
596 |
|
597 |
if (RobustCGAlgorithms.isCCW(coords)) {
|
598 |
System.out.println("izquierda,arriba,true");
|
599 |
return true;
|
600 |
} else{
|
601 |
System.out.println("izquierda,arriba,false");
|
602 |
}
|
603 |
}else {
|
604 |
if (!RobustCGAlgorithms.isCCW(coords)) {
|
605 |
System.out.println("izquierda,abajo,true");
|
606 |
return true;
|
607 |
} else{
|
608 |
System.out.println("izquierda,abajo,false");
|
609 |
}
|
610 |
}
|
611 |
}else if (lastp.getX()>antp.getX()){
|
612 |
*/
|
613 |
|
614 |
/*
|
615 |
System.out.println("angleDifl 2 1= " +
|
616 |
angleDistance(angle2, angle1));
|
617 |
System.out.println("angleDifl 1 2= " +
|
618 |
angleDistance(angle1, angle2));
|
619 |
*/
|
620 |
|
621 |
if (angleDistance(angle2, angle1) > Math.PI) { |
622 |
if (RobustCGAlgorithms.isCCW(coords)) {
|
623 |
// System.out.println("derecha,arriba,true");
|
624 |
|
625 |
return true; |
626 |
} else {
|
627 |
// System.out.println("derecha,arriba,false");
|
628 |
} |
629 |
} else {
|
630 |
if (!RobustCGAlgorithms.isCCW(coords)) {
|
631 |
// System.out.println("derecha,abajo,true");
|
632 |
|
633 |
return true; |
634 |
} else {
|
635 |
// System.out.println("derecha,abajo,false");
|
636 |
} |
637 |
} |
638 |
|
639 |
//}
|
640 |
} catch (Exception e) { |
641 |
// System.out.println("false");
|
642 |
|
643 |
return true; |
644 |
} |
645 |
|
646 |
return false; |
647 |
} |
648 |
|
649 |
|
650 |
|
651 |
|
652 |
} |