Revision 1451 branches/pilotoDWG/libraries/libFMap/src/com/iver/cit/gvsig/fmap/edition/cad/TrigonometricalFunctions.java
TrigonometricalFunctions.java | ||
---|---|---|
43 | 43 |
*/ |
44 | 44 |
package com.iver.cit.gvsig.fmap.edition.cad; |
45 | 45 |
|
46 |
import com.vividsolutions.jts.algorithm.RobustCGAlgorithms; |
|
47 |
import com.vividsolutions.jts.geom.Coordinate; |
|
48 |
|
|
46 | 49 |
import java.awt.geom.Arc2D; |
47 | 50 |
import java.awt.geom.Point2D; |
48 | 51 |
import java.awt.geom.Rectangle2D; |
49 | 52 |
|
50 |
import com.vividsolutions.jts.algorithm.RobustCGAlgorithms; |
|
51 |
import com.vividsolutions.jts.geom.Coordinate; |
|
52 | 53 |
|
53 |
|
|
54 | 54 |
/** |
55 | 55 |
* Funciones de utilidad relacionadas con trigonometr?a |
56 | 56 |
*/ |
57 | 57 |
public class TrigonometricalFunctions { |
58 | 58 |
/** |
59 |
* DOCUMENT ME! |
|
59 |
* Obtiene un par de puntos que definen la recta perpendicular a |
|
60 |
* p1-p2 que pasa por el punto perp |
|
60 | 61 |
* |
61 |
* @param angle1 DOCUMENT ME!
|
|
62 |
* @param angle2 DOCUMENT ME!
|
|
63 |
* @param angle3 DOCUMENT ME!
|
|
62 |
* @param p1 punto de la recta p1-p2
|
|
63 |
* @param p2 punto de la recta p1-p2
|
|
64 |
* @param perp Punto por el que pasa la recta perpendicular
|
|
64 | 65 |
* |
65 |
* @return -1 si los ?ngulos est?n en el sentido antihorario y 1 si est?n en sentido horario
|
|
66 |
* @return Array con dos puntos que definen la recta resultante
|
|
66 | 67 |
*/ |
67 |
// public static int getDirection(double angle1, double angle2, double angle3) { |
|
68 |
public static boolean getDirection(Point2D p1, Point2D p2, Point2D p3) { |
|
69 |
Coordinate[] coords = new Coordinate[4]; |
|
70 |
coords[0] = new Coordinate(p1.getX(), p1.getY()); |
|
71 |
coords[1] = new Coordinate(p2.getX(), p2.getY()); |
|
72 |
coords[2] = new Coordinate(p3.getX(), p3.getY()); |
|
73 |
coords[3] = new Coordinate(p1.getX(), p1.getY()); |
|
74 |
|
|
75 |
return RobustCGAlgorithms.isCCW(coords); |
|
76 |
|
|
77 |
/* System.err.println(angle1); |
|
78 |
System.err.println(angle2); |
|
79 |
System.err.println(angle3); |
|
80 |
boolean c12 = angle1 < angle2; |
|
81 |
boolean c13 = angle1 < angle3; |
|
82 |
boolean c23 = angle2 < angle3; |
|
83 |
if (c12 && c13 && c23){ |
|
84 |
return -1; |
|
85 |
}else if (c12 && c13 && !c23){ |
|
86 |
return 1; |
|
87 |
}else if (c12 && !c13 && c23){ |
|
88 |
return |
|
89 |
}else if (c12 && c13 && !c23){ |
|
90 |
}else if (c12 && c13 && !c23){ |
|
91 |
}else if (c12 && c13 && !c23){ |
|
92 |
}else if (c12 && c13 && !c23){ |
|
93 |
|
|
94 |
} |
|
95 |
|
|
96 |
if (angle1 < angle2){ |
|
97 |
if (angle3 < angle1){ |
|
98 |
angle3 = angle3 + Math.PI *2; |
|
99 |
if ((angle3>angle1) && (angle3<angle2)){ |
|
100 |
return 1; |
|
101 |
}else{ |
|
102 |
return -1; |
|
103 |
} |
|
104 |
} |
|
105 |
if ((angle3 < angle1) || (angle3 > angle2)){ |
|
106 |
System.err.println("direccion antihorario 1"); |
|
107 |
return -1; |
|
108 |
}else{ |
|
109 |
System.err.println("direccion horario 1"); |
|
110 |
return 1; |
|
111 |
} |
|
112 |
}else{ |
|
113 |
if (angle3 > angle1){ |
|
114 |
angle3 = angle3 - Math.PI *2; |
|
115 |
if ((angle3>angle1) && (angle3<angle2)){ |
|
116 |
return 1; |
|
117 |
}else{ |
|
118 |
return -1; |
|
119 |
} |
|
120 |
} |
|
121 |
if ((angle3 < angle1) || (angle3 > angle2)){ |
|
122 |
System.err.println("direccion antihorario 2"); |
|
123 |
return -1; |
|
124 |
}else{ |
|
125 |
System.err.println("direccion horario 2"); |
|
126 |
return 1; |
|
127 |
} |
|
128 |
}*/ |
|
68 |
public static Point2D[] getPerpendicular(Point2D p1, Point2D p2, |
|
69 |
Point2D perp) { |
|
70 |
//Pendiente de la recta perpendicular |
|
71 |
double m = (p1.getX() - p2.getX()) / (p2.getY() - p1.getY()); |
|
72 |
|
|
73 |
//b de la funcion de la recta perpendicular |
|
74 |
double b = p2.getY() - |
|
75 |
(m * ((perp.getX() - p2.getX()) / (p2.getY() - perp.getY()))); |
|
76 |
|
|
77 |
//Obtenemos un par de puntos |
|
78 |
Point2D[] res = new Point2D[2]; |
|
79 |
res[0] = new Point2D.Double(0, (m * 0) + b); |
|
80 |
res[1] = new Point2D.Double(1, (m * 1) + b); |
|
81 |
|
|
82 |
return res; |
|
129 | 83 |
} |
130 | 84 |
|
131 | 85 |
/** |
... | ... | |
139 | 93 |
* @return Arco |
140 | 94 |
*/ |
141 | 95 |
public static Arc2D createArc(Point2D p1, Point2D p2, Point2D p3) { |
96 |
Coordinate[] coords = new Coordinate[4]; |
|
97 |
coords[0] = new Coordinate(p1.getX(), p1.getY()); |
|
98 |
coords[1] = new Coordinate(p2.getX(), p2.getY()); |
|
99 |
coords[2] = new Coordinate(p3.getX(), p3.getY()); |
|
100 |
coords[3] = new Coordinate(p1.getX(), p1.getY()); |
|
101 |
|
|
142 | 102 |
Point2D center = getCircleCenter(p1, p2, p3); |
143 | 103 |
double angle1 = getAngle(center, p1); |
144 | 104 |
double angle2 = getAngle(center, p3); |
145 | 105 |
double extent = angleDistance(angle1, angle2); |
146 |
if (!getDirection(p1, p2, p3)){//, getAngle(center, p2), angle2) == 1){ |
|
147 |
extent = Math.PI * 2 - extent; |
|
148 |
}else{ |
|
106 |
|
|
107 |
if (!RobustCGAlgorithms.isCCW(coords)) { |
|
108 |
extent = (Math.PI * 2) - extent; |
|
109 |
} else { |
|
149 | 110 |
extent = -extent; |
150 | 111 |
} |
151 | 112 |
|
... | ... | |
162 | 123 |
|
163 | 124 |
Rectangle2D.Double rBounds = new Rectangle2D.Double(xR, yR, w, h); |
164 | 125 |
Arc2D.Double resul = new Arc2D.Double(rBounds, |
165 |
Math.toDegrees((Math.PI * 2) - angle1), |
|
166 |
Math.toDegrees(extent), Arc2D.OPEN);
|
|
126 |
Math.toDegrees((Math.PI * 2) - angle1), Math.toDegrees(extent),
|
|
127 |
Arc2D.OPEN); |
|
167 | 128 |
|
168 | 129 |
return resul; |
169 | 130 |
} |
Also available in: Unified diff