Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.geometry / org.gvsig.fmap.geometry.jts / src / main / java / org / gvsig / fmap / geom / jts / util / UtilFunctions.java @ 42283

History | View | Annotate | Download (19.9 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.fmap.geom.jts.util;
25

    
26
import java.awt.Shape;
27
import java.awt.geom.AffineTransform;
28
import java.awt.geom.Arc2D;
29
import java.awt.geom.Ellipse2D;
30
import java.awt.geom.Line2D;
31
import java.awt.geom.Point2D;
32
import java.awt.geom.Rectangle2D;
33

    
34
import org.slf4j.Logger;
35
import org.slf4j.LoggerFactory;
36

    
37
import org.gvsig.fmap.geom.Geometry;
38
import org.gvsig.fmap.geom.GeometryLocator;
39
import org.gvsig.fmap.geom.GeometryManager;
40
import org.gvsig.fmap.geom.primitive.Curve;
41

    
42
//import com.vividsolutions.jts.algorithm.RobustCGAlgorithms;
43
//import com.vividsolutions.jts.geom.Coordinate;
44

    
45
/**
46
 * @author FJP
47
 *
48
 *         TODO To change the template for this generated type comment go to
49
 *         Window - Preferences - Java - Code Generation - Code and Comments
50
 * @deprecated to be removed or moved from API to implementation in gvSIG 2.1.0
51
 */
52
public class UtilFunctions {
53
        private static final Logger logger = LoggerFactory.getLogger(GeometryManager.class);
54

    
55
        static public Arc2D createCircle(Point2D p1, Point2D p2, Point2D p3) //, Graphics g)
56
    {
57
        double xC, yC, w, h;
58

    
59
        // Calculamos 2 secantes, tiramos perpendiculares por sus puntos
60
        // medios y obtenemos el centro. Luego calculamos el radio.
61
        // Puntos medios de los segmentos.
62
        double xm1, ym1, xm2, ym2;
63
        xm1 = (p1.getX() + p2.getX())/ 2.0;
64
        ym1 = (p1.getY() + p2.getY())/ 2.0;
65
        xm2 = (p2.getX() + p3.getX())/ 2.0;
66
        ym2 = (p2.getY() + p3.getY())/ 2.0;
67

    
68
        /* g.setColor(Color.GRAY);
69
        g.draw3DRect((int)xm1, (int) ym1, 1, 1, true);
70
        g.draw3DRect((int)xm2, (int) ym2, 1, 1, true); */
71
        // Pendientes de las perpendiculares y constantes
72
        double mP1=0, mP2=0, A1, A2;
73
        boolean bPerp1 = false;
74
        //boolean bPerp2 = false;
75
        if (p2.getY() - p1.getY() == 0)
76
        {
77
            A1 = ym1;
78
            bPerp1 = true;
79
        }
80
        else
81
        {
82
            mP1 = (p2.getX() - p1.getX()) /(p1.getY() - p2.getY());
83
            A1 = ym1 - xm1 * mP1;
84
        }
85
        if (p2.getY() - p3.getY() == 0)
86
        {
87
            A2 = ym2;
88
            //bPerp2 = true;
89
        }
90
        else
91
        {
92
            mP2 = (p3.getX() - p2.getX()) /(p2.getY() - p3.getY());
93
            A2 = ym2 - xm2 * mP2;
94
        }
95
        if (mP2 == mP1)
96
        {
97
            return null; // Error, 3 puntos alineados. No puede pasar un arco
98
        }
99
        else
100
        {
101
            xC = (A2 - A1)/(mP1-mP2);
102
            if (!bPerp1) {
103
                                yC = xC * mP1 + A1;
104
                        } else {
105
                                yC = xC * mP2 + A2;
106
                        }
107
        }
108
        double Radio = p1.distance(xC, yC);
109
        double xR = xC - Radio ;
110
        double yR = yC - Radio ;
111
        w = 2.0* Radio;
112
        h = w;
113
        Rectangle2D.Double rBounds = new Rectangle2D.Double(xR,yR, w,h);
114
        Arc2D.Double resul = new Arc2D.Double(rBounds, 0.0, 360.0, Arc2D.OPEN);
115
                /* g.setColor(Color.RED);
116
                ((Graphics2D) g).draw(resul);
117
                g.setColor(Color.BLUE);
118
                ((Graphics2D) g).draw(rBounds);
119
                g.draw3DRect((int)p1.getX(), (int) p1.getY(), 1, 1, true);
120
                g.draw3DRect((int)p2.getX(), (int) p2.getY(), 2, 2, true);
121
                g.draw3DRect((int)p3.getX(), (int) p3.getY(), 1, 1, true);
122
                g.drawString("1", (int) p1.getX(), (int) p1.getY());
123
                g.drawString("2", (int) p2.getX(), (int) p2.getY());
124
                g.drawString("3", (int) p3.getX(), (int) p3.getY());
125
                g.drawString("C", (int) xC, (int) yC);
126
                g.draw3DRect((int)xC, (int) yC, 2, 2, true); */
127

    
128
        return resul;
129
    }
130

    
131
        static public Arc2D createCircle(Point2D center, double radious){
132
        double xR = center.getX() - radious ;
133
        double yR = center.getY() - radious ;
134
        double w = 2.0 * radious;
135
        double h = w;
136
        Rectangle2D.Double rBounds = new Rectangle2D.Double(xR,yR, w,h);
137
        Arc2D.Double resul = new Arc2D.Double(rBounds, 0.0, 360.0, Arc2D.OPEN);
138
        return resul;
139
        }
140

    
141
        static public Shape createEllipse(Point2D init, Point2D end, double ydist){
142
            double h = ydist*2;
143
            double w = init.distance(end);
144
            double x = init.getX();
145
            double y = init.getY();
146

    
147
            Ellipse2D.Double result = new Ellipse2D.Double(x, y-(h/2), w, h);
148
            return AffineTransform.getRotateInstance(getAngle(init,end), x, y).createTransformedShape(result);
149
//        return AffineTransform.getRotateInstance(getAngle(init,end), x, y).createTransformedShape(new Ellipse2D.Double(0, 0, 2, 1));
150
        }
151

    
152
    /**
153
         * Obtiene un par de puntos que definen la recta perpendicular a p1-p2 que
154
         * pasa por el punto perp
155
         *
156
         * @param p1 punto de la recta p1-p2
157
         * @param p2 punto de la recta p1-p2
158
         * @param perp Punto por el que pasa la recta perpendicular, debe ser
159
         *                   distinto a p2
160
         *
161
         * @return Array con dos puntos que definen la recta resultante
162
         * @deprecated
163
         *         use the perpendicular operation
164
         */
165
        public static Point2D[] getPerpendicular(Point2D p1, Point2D p2,
166
                Point2D perp) {
167
                if ((p2.getY() - p1.getY()) == 0) {
168
                        return new Point2D[] {
169
                                new Point2D.Double(perp.getX(), 0),
170
                                new Point2D.Double(perp.getX(), 1)
171
                        };
172
                }
173

    
174
                //Pendiente de la recta perpendicular
175
                double m = (p1.getX() - p2.getX()) / (p2.getY() - p1.getY());
176

    
177
                //b de la funcion de la recta perpendicular
178
                double b = perp.getY() - (m * perp.getX());
179

    
180
                //Obtenemos un par de puntos
181
                Point2D[] res = new Point2D[2];
182

    
183
                res[0] = new Point2D.Double(0, (m * 0) + b);
184
                res[1] = new Point2D.Double(1000, (m * 1000) + b);
185

    
186
                return res;
187
        }
188
        public static Point2D[] getParallel(Point2D p1,Point2D p2,double distance) {
189
                Point2D[] pParallel=new Point2D[2];
190
                pParallel[0]=getPerpendicularPoint(p1,p2,p1,distance);
191
                pParallel[1]=getPerpendicularPoint(p1,p2,p2,distance);
192
                return pParallel;
193
        }
194

    
195
        /**
196
         * Obtiene el punto que se encuentra a una distancia 'dist' de la recta
197
         * p1-p2 y se encuentra en la recta perpendicular que pasa por perpPoint
198
         *
199
         * @param p1 Punto de la recta p1-p2
200
         * @param p2 Punto de la recta p1-p2
201
         * @param perpPoint Punto de la recta perpendicular
202
         * @param dist Distancia del punto que se quiere obtener a la recta p1-p2
203
         *
204
         * @return DOCUMENT ME!
205
         * @deprecated
206
         *         Use the perpendicularPoint operation
207
         */
208
        public static Point2D getPerpendicularPoint(Point2D p1, Point2D p2,
209
                Point2D perpPoint, double dist) {
210
                Point2D[] p = getPerpendicular(p1, p2, perpPoint);
211
                Point2D unit = getUnitVector(p[0], p[1]);
212

    
213
                return new Point2D.Double(perpPoint.getX() + (unit.getX() * dist),
214
                        perpPoint.getY() + (unit.getY() * dist));
215
        }
216

    
217
        /**
218
         * Devuelve un vector unitario en forma de punto a partir de dos puntos.
219
         *
220
         * @param p1 punto origen.
221
         * @param p2 punto destino.
222
         *
223
         * @return vector unitario.
224
         * @deprecated
225
         *         use the UnitVector operation
226
         */
227
        public static Point2D getUnitVector(Point2D p1, Point2D p2) {
228
                Point2D paux = new Point2D.Double(p2.getX() - p1.getX(),
229
                                p2.getY() - p1.getY());
230
                double v = Math.sqrt(Math.pow(paux.getX(), 2d) +
231
                                Math.pow(paux.getY(), 2d));
232
                paux = new Point2D.Double(paux.getX() / v, paux.getY() / v);
233

    
234
                return paux;
235
        }
236
        /**
237
         * Obtiene el centro del c�rculo que pasa por los tres puntos que se pasan
238
         * como  par�metro
239
         *
240
         * @param p1 primer punto del c�rculo cuyo centro se quiere obtener
241
         * @param p2 segundo punto del c�rculo cuyo centro se quiere obtener
242
         * @param p3 tercer punto del c�rculo cuyo centro se quiere obtener
243
         *
244
         * @return Devuelve null si los puntos est�n alineados o no son 3 puntos
245
         *                    distintos
246
         */
247
        public static Point2D getCenter(Point2D p1, Point2D p2, Point2D p3) {
248
                if (p1.equals(p2) || p2.equals(p3) || p1.equals(p3)) {
249
                        return null;
250
                }
251

    
252
                Point2D[] perp1 = getPerpendicular(p1, p2,
253
                                new Point2D.Double((p1.getX() + p2.getX()) / 2,
254
                                        (p1.getY() + p2.getY()) / 2));
255
                Point2D[] perp2 = getPerpendicular(p2, p3,
256
                                new Point2D.Double((p2.getX() + p3.getX()) / 2,
257
                                        (p2.getY() + p3.getY()) / 2));
258

    
259
                return getIntersection(perp1[0], perp1[1], perp2[0], perp2[1]);
260
        }
261

    
262

    
263
        /**
264
         * Devuelve el punto de la intersecci�n entre las lineas p1-p2 y p3-p4.
265
         *
266
         * @param p1 punto de la recta p1-p2
267
         * @param p2 punto de la recta p1-p2
268
         * @param p3 punto de la recta p3-p4
269
         * @param p4 punto de la recta p3-p4
270
         *
271
         * @return DOCUMENT ME!
272
         *
273
         * @throws RuntimeException DOCUMENT ME!
274
         */
275
        public static Point2D getIntersection(Point2D p1, Point2D p2, Point2D p3,
276
                Point2D p4) {
277
                double m1 = Double.POSITIVE_INFINITY;
278

    
279
                if ((p2.getX() - p1.getX()) != 0) {
280
                        m1 = (p2.getY() - p1.getY()) / (p2.getX() - p1.getX());
281
                }
282

    
283
                double m2 = Double.POSITIVE_INFINITY;
284

    
285
                if ((p4.getX() - p3.getX()) != 0) {
286
                        m2 = (p4.getY() - p3.getY()) / (p4.getX() - p3.getX());
287
                }
288

    
289
                if ((m1 == Double.POSITIVE_INFINITY) &&
290
                                (m2 == Double.POSITIVE_INFINITY)) {
291
                        return null;
292
                }
293

    
294
                double b1 = p2.getY() - (m1 * p2.getX());
295

    
296
                double b2 = p4.getY() - (m2 * p4.getX());
297

    
298
                if ((m1 != Double.POSITIVE_INFINITY) &&
299
                                (m2 != Double.POSITIVE_INFINITY)) {
300
                        if (m1 == m2) {
301
                                return null;
302
                        }
303

    
304
                        double x = (b2 - b1) / (m1 - m2);
305

    
306
                        return new Point2D.Double(x, (m1 * x) + b1);
307
                } else if (m1 == Double.POSITIVE_INFINITY) {
308
                        double x = p1.getX();
309

    
310
                        return new Point2D.Double(x, (m2 * x) + b2);
311
                } else if (m2 == Double.POSITIVE_INFINITY) {
312
                        double x = p3.getX();
313

    
314
                        return new Point2D.Double(x, (m1 * x) + b1);
315
                }
316

    
317
                //no llega nunca
318
                throw new RuntimeException("BUG!");
319
        }
320
        /**
321
         * Obtiene el �ngulo del vector que se pasa como par�metro con el vector
322
         * horizontal de izquierda a derecha
323
         *
324
         * @param start punto origen del vector
325
         * @param end punto destino del vector
326
         *
327
         * @return angulo en radianes
328
         */
329
        public static double getAngle(Point2D start, Point2D end) {
330
                double angle = Math.acos((end.getX() - start.getX()) / start.distance(
331
                                        end));
332

    
333
                if (start.getY() > end.getY()) {
334
                        angle = -angle;
335
                }
336

    
337
                if (angle < 0) {
338
                        angle += (2 * Math.PI);
339
                }
340

    
341
                return angle;
342
        }
343
        /**
344
         * Devuelve la distancia desde angle1 a angle2. Angulo en radianes de
345
         * diferencia entre angle1 y angle2 en sentido antihorario
346
         *
347
         * @param angle1 angulo en radianes. Debe ser positivo y no dar ninguna
348
         *                   vuelta a la circunferencia
349
         * @param angle2 angulo en radianes. Debe ser positivo y no dar ninguna
350
         *                   vuelta a la circunferencia
351
         *
352
         * @return distancia entre los �ngulos
353
         */
354
        public static double angleDistance(double angle1, double angle2) {
355
                if (angle1 < angle2) {
356
                        return angle2 - angle1;
357
                } else {
358
                        return ((Math.PI * 2) - angle1) + angle2;
359
                }
360
        }
361
        /**
362
         * Devuelve el punto de la recta que viene dada por los puntos p1 y p2 a
363
         * una distancia radio de p1.
364
         *
365
         * @param p1 DOCUMENT ME!
366
         * @param p2 DOCUMENT ME!
367
         * @param radio DOCUMENT ME!
368
         *
369
         * @return DOCUMENT ME!
370
         */
371
        public static Point2D getPoint(Point2D p1, Point2D p2, double radio) {
372
                Point2D paux = new Point2D.Double(p2.getX() - p1.getX(),
373
                                p2.getY() - p1.getY());
374
                double v = Math.sqrt(Math.pow(paux.getX(), 2d) +
375
                                Math.pow(paux.getY(), 2d));
376
                paux = new Point2D.Double(paux.getX() / v, paux.getY() / v);
377

    
378
                Point2D aux1 = new Point2D.Double(p1.getX() + (radio * paux.getX()),
379
                                p1.getY() + (radio * paux.getY()));
380

    
381
                return aux1;
382
        }
383
        /**
384
         * Devuelve la menor distancia desde angle1 a angle2.
385
         *
386
         * @param angle1 angulo en radianes. Debe ser positivo y no dar ninguna
387
         *                   vuelta a la circunferencia
388
         * @param angle2 angulo en radianes. Debe ser positivo y no dar ninguna
389
         *                   vuelta a la circunferencia
390
         *
391
         * @return distancia entre los �ngulos
392
         */
393
        public static double absoluteAngleDistance(double angle1, double angle2) {
394
                double d = Math.abs(angle1 - angle2);
395

    
396
                if (d < Math.PI) {
397
                        return d;
398
                } else {
399
                        if (angle1 < angle2) {
400
                                angle2 -= (Math.PI * 2);
401
                        } else {
402
                                angle1 -= (Math.PI * 2);
403
                        }
404

    
405
                        return Math.abs(angle1 - angle2);
406
                }
407
        }
408
        /**
409
         * Obtiene un arco a partir de 3 puntos. Devuelve null si no se puede crear
410
         * el arco porque los puntos est�n alineados o los 3 puntos no son
411
         * distintos
412
         *
413
         * @param p1
414
         * @param p2
415
         * @param p3
416
         *
417
         * @return Arco
418
         */
419
        public static Arc2D createArc(Point2D p1, Point2D p2, Point2D p3) {
420
                Point2D center = getCenter(p1, p2, p3);
421

    
422
                double angle1;
423
                double angle2;
424
                double extent;
425

    
426
                if (center == null) {
427
                        if (p1.equals(p3) && !p2.equals(p1)) {
428
                                //Si los puntos p1 y p3 son los mismos (pero el p2 no),
429
                                //consideramos que el arco es una circunferencia completa
430
                                center = new Point2D.Double((p1.getX() + p2.getX()) / 2,
431
                                                        (p1.getY() + p2.getY()) / 2);
432
                                angle1 = getAngle(center, p1);
433
                                extent = Math.PI*2;
434
                        } else {
435
                                //en cualquier otro caso, no podemos crear el arco.
436
                                return null;
437
                        }
438
                } else {
439
                    angle1 = getAngle(center, p1);
440
                    angle2 = getAngle(center, p3);
441
                    extent = angleDistance(angle1, angle2);
442

    
443
                    try {
444
                        GeometryManager manager = GeometryLocator.getGeometryManager();
445
                        Curve line = manager.createCurve(Geometry.SUBTYPES.GEOM2D);
446
                        line.addVertex(p1.getX(), p1.getY());
447
                        line.addVertex(p2.getX(), p2.getY());
448
                        line.addVertex(p3.getX(), p3.getY());
449
                        line.addVertex(p1.getX(), p1.getY());
450
                        if( !line.isCCW() ) {
451
                            extent = (Math.PI * 2) - extent;
452
                        } else {
453
                            extent = -extent;
454
                        }
455
                    } catch (Exception ex) {
456
                        logger.warn("Can't determine CCW of the Arc",ex);
457
                        extent = -extent;
458
                    }
459
                }
460
                //System.err.println("angle1:" + angle1);
461
                //System.err.println("angle2:" + getAngle(center, p2));
462
                //System.err.println("angle3:" + angle2);
463
                //System.err.println("extent:" + extent);
464
                double Radio = p1.distance(center);
465
                double xR = center.getX() - Radio;
466
                double yR = center.getY() - Radio;
467
                double w = 2.0 * Radio;
468
                double h = w;
469

    
470
                Rectangle2D.Double rBounds = new Rectangle2D.Double(xR, yR, w, h);
471
                Arc2D.Double resul = new Arc2D.Double(rBounds,
472
                                Math.toDegrees((Math.PI * 2) - angle1), Math.toDegrees(extent),
473
                                Arc2D.OPEN);
474

    
475
                return resul;
476
        }
477

    
478
        /**
479
         * Obtiene un arco a partir del centro, radio, angulo inicial y extension del angulo.
480
         * Devuelve null si no lo puede crear.
481
         *
482
         * @param center
483
         * @param radius
484
         * @param angSt en radianes
485
         * @param angExt en radianes
486
         *
487
         * @return Arco
488
         */
489
        public static Arc2D createArc(Point2D center, double radius, double angSt, double angExt) {
490
                double xR = center.getX() - radius;
491
                double yR = center.getY() - radius;
492
                double w = 2.0 * radius;
493
                double h = w;
494

    
495
                Rectangle2D.Double rBounds = new Rectangle2D.Double(xR, yR, w, h);
496
                Arc2D.Double resul = new Arc2D.Double(rBounds,
497
                                Math.toDegrees((Math.PI * 2) - angSt), Math.toDegrees(angExt),
498
                                Arc2D.OPEN);
499

    
500
                return resul;
501
        }
502

    
503
        /**
504
         * Obtiene un arco a partir del
505
         *  centro del arco y punto inicio y punto final
506
         *  Suponemos un Arco definicio CCW (CounterClockWise)
507
         * @param center
508
         * @param init
509
         * @param end
510
         *
511
         * @return Arco
512
         */
513
        public static Arc2D createArc2points(Point2D center, Point2D init, Point2D end) {
514

    
515
                double angle1 = getAngle(center, init);
516
                double angle2 = getAngle(center, end);
517
                double extent = angleDistance(angle1, angle2);
518

    
519
                extent = -extent; // CCW
520

    
521
                //System.err.println("angle1:" + angle1);
522
                //System.err.println("angle2:" + getAngle(center, p2));
523
                //System.err.println("angle3:" + angle2);
524
                //System.err.println("extent:" + extent);
525
                double Radio = init.distance(center);
526
                double xR = center.getX() - Radio;
527
                double yR = center.getY() - Radio;
528
                double w = 2.0 * Radio;
529
                double h = w;
530

    
531
                Rectangle2D.Double rBounds = new Rectangle2D.Double(xR, yR, w, h);
532
                Arc2D.Double resul = new Arc2D.Double(rBounds,
533
                                Math.toDegrees((Math.PI * 2) - angle1), Math.toDegrees(extent),
534
                                Arc2D.OPEN);
535

    
536
                return resul;
537
        }
538

    
539
        /**
540
         * Devuelve el punto a una distancia radio del punto p1 y aplicandole un �ngulo an.
541
         * una distancia radio de p1.
542
         *
543
         * @param p1 DOCUMENT ME!
544
         * @param p2 DOCUMENT ME!
545
         * @param radio DOCUMENT ME!
546
         *
547
         * @return DOCUMENT ME!
548
         */
549
        public static Point2D getPoint(Point2D p1, double an, double radio) {
550
                double x=(radio*Math.cos(an))+p1.getX();
551
                double y=(radio*Math.sin(an))+p1.getY();
552

    
553
                Point2D p=new Point2D.Double(x,y);
554

    
555
                return p;
556
        }
557

    
558
        /**
559
         * Obtiene una linea a partir de dos puntos.
560
         * Devuelve null si no lo puede crear.
561
         *
562
         * @param start
563
         * @param end
564
         *
565
         * @return Linea
566
         */
567
        public static Line2D createLine(Point2D start, Point2D end) {
568
                return new Line2D.Double(start, end);
569

    
570
        }
571

    
572

    
573
        /**
574
         * DOCUMENT ME!
575
         *
576
         * @param antp DOCUMENT ME!
577
         * @param lastp DOCUMENT ME!
578
         * @param interp DOCUMENT ME!
579
         * @param point DOCUMENT ME!
580
         *
581
         * @return DOCUMENT ME!
582
         */
583
        public static boolean isLowAngle(Point2D antp, Point2D lastp,
584
                Point2D interp, Point2D point) {
585
                ///double ob=lastp.distance(point);
586
                ///Point2D[] aux=getPerpendicular(lastp,interp,point);
587
                ///Point2D intersect=getIntersection(aux[0],aux[1],lastp,interp);
588
                ///double pb=intersect.distance(point);
589
                ///double a=Math.asin(pb/ob);
590

    
591
                boolean isCCW = true;
592
                try {
593
                    GeometryManager manager = GeometryLocator.getGeometryManager();
594
                    Curve line;
595
                    line = manager.createCurve(Geometry.SUBTYPES.GEOM2D);
596
                    line.addVertex(lastp.getX(), lastp.getY());
597
                    line.addVertex(interp.getX(), interp.getY());
598
                    line.addVertex(point.getX(), point.getY());
599
                    line.addVertex(lastp.getX(), lastp.getY());
600
                    isCCW = line.isCCW();
601
                } catch (Exception ex) {
602
                    logger.warn("Can't determine CCW of angle.",ex);
603
                }
604

    
605
                try {
606
                        double angle1 = getAngle(antp, lastp);
607
                        // System.out.println("angle1= " + angle1);
608

    
609
                        double angle2 = getAngle(lastp, point);
610
                        // System.out.println("angle2= " + angle2);
611

    
612
                        /*if (lastp.getX()<antp.getX()){
613
                           System.out.println("angleDiff 2 1= "+angleDistance(angle2,angle1));
614
                           System.out.println("angleDiff 1 2= "+angleDistance(angle1,angle2));
615
                           if (angleDistance(angle2,angle1)>Math.PI){
616

617
                           if (RobustCGAlgorithms.isCCW(coords)) {
618
                                   System.out.println("izquierda,arriba,true");
619
                                   return true;
620
                           } else{
621
                                   System.out.println("izquierda,arriba,false");
622
                           }
623
                           }else {
624
                                   if (!RobustCGAlgorithms.isCCW(coords)) {
625
                                           System.out.println("izquierda,abajo,true");
626
                                           return true;
627
                                   } else{
628
                                           System.out.println("izquierda,abajo,false");
629
                                   }
630
                           }
631
                           }else if (lastp.getX()>antp.getX()){
632
                         */
633

    
634
                        /*
635
                        System.out.println("angleDifl 2 1= " +
636
                                angleDistance(angle2, angle1));
637
                        System.out.println("angleDifl 1 2= " +
638
                                angleDistance(angle1, angle2));
639
                        */
640

    
641
                        if (angleDistance(angle2, angle1) > Math.PI) {
642
                                if (isCCW) {
643
                                        // System.out.println("derecha,arriba,true");
644

    
645
                                        return true;
646
                                } else {
647
                                        // System.out.println("derecha,arriba,false");
648
                                }
649
                        } else {
650
                                if (!isCCW) {
651
                                        // System.out.println("derecha,abajo,true");
652

    
653
                                        return true;
654
                                } else {
655
                                    // System.out.println("derecha,abajo,false");
656
                                }
657
                        }
658

    
659
                        //}
660
                } catch (Exception e) {
661
                        // System.out.println("false");
662

    
663
                        return true;
664
                }
665

    
666
                return false;
667
        }
668

    
669

    
670

    
671

    
672
}