root / trunk / org.gvsig.dwg / org.gvsig.dwg.lib / src / main / java / org / gvsig / dwg / lib / util / FMapUtil.java @ 5
History | View | Annotate | Download (4.41 KB)
1 |
/*
|
---|---|
2 |
* Created on 18-ene-2007 by azabala
|
3 |
*
|
4 |
*/
|
5 |
package org.gvsig.dwg.lib.util; |
6 |
|
7 |
import java.awt.geom.Point2D; |
8 |
import java.util.Iterator; |
9 |
import java.util.List; |
10 |
|
11 |
import org.gvsig.dwg.lib.IDwgVertex; |
12 |
import org.gvsig.fmap.geom.Geometry; |
13 |
import org.gvsig.fmap.geom.GeometryLocator; |
14 |
import org.gvsig.fmap.geom.GeometryManager; |
15 |
import org.gvsig.fmap.geom.aggregate.MultiCurve; |
16 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
17 |
import org.gvsig.fmap.geom.primitive.Curve; |
18 |
import org.gvsig.fmap.geom.primitive.Point; |
19 |
import org.gvsig.fmap.geom.primitive.Surface; |
20 |
|
21 |
|
22 |
/**
|
23 |
* @author alzabord
|
24 |
*
|
25 |
*/
|
26 |
public class FMapUtil { |
27 |
|
28 |
// /**
|
29 |
// * Method that changes a Point3D array to a FPolyline3D. Is useful to
|
30 |
// * convert a polyline given by it points to a FPolyline3D, a polyline 3D in
|
31 |
// * the FMap model object
|
32 |
// *
|
33 |
// * @param pts
|
34 |
// * Array of Point3D that defines the polyline 3D that will be
|
35 |
// * converted in a FPolyline3D
|
36 |
// * @return FPolyline3D This FPolyline3D is build using the array of Point3D
|
37 |
// * that is the argument of the method
|
38 |
// */
|
39 |
// public static FPolyline3D points3DToFPolyline3D(List pts) {
|
40 |
// GeneralPathX genPathX = getGeneralPathX(pts);
|
41 |
// double[] elevations = new double[pts.size()];
|
42 |
// for (int i = 0; i < pts.size(); i++) {
|
43 |
// elevations[i] = ((double[])pts.get(i))[2];
|
44 |
// }
|
45 |
// return new FPolyline3D(genPathX, elevations);
|
46 |
// }
|
47 |
|
48 |
private static GeometryManager gManager = GeometryLocator |
49 |
.getGeometryManager(); |
50 |
|
51 |
|
52 |
|
53 |
// /**
|
54 |
// * Method that changes a Point2D array to a FPolyline2D. Is useful to
|
55 |
// * convert a polyline given by it points to a FPolyline2D, a polyline in the
|
56 |
// * FMap model object
|
57 |
// *
|
58 |
// * @param pts
|
59 |
// * Array of Point2D that defines the polyline that will be
|
60 |
// * converted in a FPolyline2D
|
61 |
// * @return FPolyline2D This FPolyline2D is build using the array of Point2D
|
62 |
// * that is the argument of the method
|
63 |
// */
|
64 |
// public static FPolyline2D points2DToFPolyline2D(List pts) {
|
65 |
// GeneralPathX genPathX = getGeneralPathX(pts);
|
66 |
// return new FPolyline2D(genPathX);
|
67 |
// }
|
68 |
|
69 |
public static MultiCurve ptsToMultiCurve(List pts, int subType) |
70 |
throws CreateGeometryException {
|
71 |
|
72 |
if (pts.size() < 2) { |
73 |
throw new IllegalArgumentException(); |
74 |
} |
75 |
|
76 |
Point point, prevPoint;
|
77 |
Curve curve; |
78 |
|
79 |
MultiCurve multi = (MultiCurve) gManager.create( |
80 |
Geometry.TYPES.MULTICURVE, |
81 |
subType); |
82 |
prevPoint = FMapUtil.createPoint(subType, pts.get(0));
|
83 |
for (int i = 1; i < pts.size(); i++) { |
84 |
point = FMapUtil.createPoint(subType, pts.get(i)); |
85 |
curve = (Curve) gManager.create(Geometry.TYPES.CURVE, subType); |
86 |
curve.setPoints(prevPoint, point); |
87 |
multi.addCurve(curve); |
88 |
prevPoint = FMapUtil.createPoint(subType, pts.get(i)); |
89 |
} |
90 |
return multi;
|
91 |
|
92 |
} |
93 |
|
94 |
public static Surface ptsToPolygon(List pts, int subType) |
95 |
throws CreateGeometryException {
|
96 |
|
97 |
|
98 |
if (pts.size() < 3) { |
99 |
throw new IllegalArgumentException(); |
100 |
} |
101 |
|
102 |
Point cur;
|
103 |
Surface surface = (Surface) gManager.create(Geometry.TYPES.SURFACE, |
104 |
subType); |
105 |
|
106 |
Iterator iter = pts.iterator();
|
107 |
while (iter.hasNext()) {
|
108 |
cur = createPoint(subType, iter.next()); |
109 |
surface.addVertex(cur); |
110 |
} |
111 |
return surface;
|
112 |
} |
113 |
|
114 |
public static Point createPoint(int subType, |
115 |
Object point)
|
116 |
throws CreateGeometryException {
|
117 |
Point result = (Point) gManager.create(Geometry.TYPES.POINT, subType); |
118 |
if (point instanceof double[]) { |
119 |
result.setCoordinates((double[]) point); |
120 |
} else if (point instanceof Point2D) { |
121 |
Point2D p = (Point2D) point; |
122 |
result.setX(p.getX()); |
123 |
result.setY(p.getY()); |
124 |
|
125 |
} else if (point instanceof IDwgVertex) { |
126 |
result.setCoordinates(((IDwgVertex) point).getPoint()); |
127 |
} else {
|
128 |
throw new IllegalArgumentException(); |
129 |
} |
130 |
return result;
|
131 |
} |
132 |
|
133 |
/**
|
134 |
* Devuelve la distancia desde angle1 a angle2. Angulo en radianes de
|
135 |
* diferencia entre angle1 y angle2 en sentido antihorario
|
136 |
*
|
137 |
* @param angle1 angulo en radianes. Debe ser positivo y no dar ninguna
|
138 |
* vuelta a la circunferencia
|
139 |
* @param angle2 angulo en radianes. Debe ser positivo y no dar ninguna
|
140 |
* vuelta a la circunferencia
|
141 |
*
|
142 |
* @return distancia entre los �ngulos
|
143 |
*/
|
144 |
public static double angleDistance(double angle1, double angle2) { |
145 |
if (angle1 < angle2) {
|
146 |
return angle2 - angle1;
|
147 |
} else {
|
148 |
return ((Math.PI * 2) - angle1) + angle2; |
149 |
} |
150 |
} |
151 |
} |