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 / primitive / curve / arc / Arc2DZ.java @ 42267
History | View | Annotate | Download (6.53 KB)
1 |
/* gvSIG. Desktop Geographic Information System.
|
---|---|
2 |
*
|
3 |
* Copyright ? 2007-2015 gvSIG Association
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
18 |
* MA 02110-1301, USA.
|
19 |
*
|
20 |
* For any additional information, do not hesitate to contact us
|
21 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
22 |
*/
|
23 |
package org.gvsig.fmap.geom.jts.primitive.curve.arc; |
24 |
|
25 |
import java.awt.geom.PathIterator; |
26 |
|
27 |
import com.vividsolutions.jts.geom.Coordinate; |
28 |
|
29 |
import org.gvsig.fmap.geom.Geometry; |
30 |
import org.gvsig.fmap.geom.jts.primitive.point.Point3D; |
31 |
import org.gvsig.fmap.geom.jts.primitive.point.PointJTS; |
32 |
import org.gvsig.fmap.geom.jts.util.ArrayListCoordinateSequence; |
33 |
import org.gvsig.fmap.geom.jts.util.JTSUtils; |
34 |
import org.gvsig.fmap.geom.primitive.Point; |
35 |
|
36 |
/**
|
37 |
* @author fdiaz
|
38 |
*
|
39 |
*/
|
40 |
public class Arc2DZ extends AbstractArc { |
41 |
|
42 |
/**
|
43 |
*
|
44 |
*/
|
45 |
private static final long serialVersionUID = -5691008010954470053L; |
46 |
private double zValue = Double.NaN; |
47 |
|
48 |
/**
|
49 |
* @param subtype
|
50 |
*/
|
51 |
protected Arc2DZ() {
|
52 |
super(Geometry.SUBTYPES.GEOM3D);
|
53 |
} |
54 |
|
55 |
/*
|
56 |
* (non-Javadoc)
|
57 |
*
|
58 |
* @see
|
59 |
* org.gvsig.fmap.geom.primitive.Arc#setPoints(org.gvsig.fmap.geom.primitive
|
60 |
* .Point, double, double, double)
|
61 |
*/
|
62 |
public void setPoints(Point center, double radius, double startAngle, double angleExt) { |
63 |
center = fixPoint(center); |
64 |
|
65 |
double x;
|
66 |
double y;
|
67 |
double w;
|
68 |
double h;
|
69 |
double start;
|
70 |
double extent;
|
71 |
double angleOffset;
|
72 |
final double pi2 = Math.PI * 2; |
73 |
|
74 |
angleOffset = 0;
|
75 |
if (angleExt < 0) { |
76 |
angleOffset = pi2 + angleExt; |
77 |
angleExt = Math.abs(angleExt);
|
78 |
} |
79 |
x = center.getX() - radius; |
80 |
y = center.getY() - radius; |
81 |
w = radius * 2;
|
82 |
h = w; // Son siempre arcos de circunferencia
|
83 |
|
84 |
if (angleExt > 0 && (angleExt % pi2) == 0) { |
85 |
start = 0;
|
86 |
extent = 360;
|
87 |
} else {
|
88 |
angleExt = angleExt % pi2; // Asumimos que aqui angleExt es siempre
|
89 |
// positivo
|
90 |
startAngle = Math.abs(startAngle) % pi2;
|
91 |
start = Math.toDegrees(pi2 - startAngle + angleOffset);
|
92 |
extent = -Math.toDegrees(pi2 - angleExt);
|
93 |
} |
94 |
|
95 |
double angleStart = Math.toRadians(-start); |
96 |
double initX = x + (Math.cos(angleStart) * 0.5 + 0.5) * radius * 2; |
97 |
double initY = y + (Math.sin(angleStart) * 0.5 + 0.5) * radius * 2; |
98 |
init = new Point3D(initX, initY, ((Point3D) center).getZ());
|
99 |
|
100 |
double angleEnd = Math.toRadians(-start - extent); |
101 |
double endX = x + (Math.cos(angleEnd) * 0.5 + 0.5) * radius * 2; |
102 |
double endY = y + (Math.sin(angleEnd) * 0.5 + 0.5) * radius * 2; |
103 |
end = new Point3D(endX, endY, ((Point3D) center).getZ());
|
104 |
|
105 |
double angleMiddle = Math.toRadians(-start - extent) / 2; |
106 |
double middleX = x + (Math.cos(angleMiddle) * 0.5 + 0.5) * radius * 2; |
107 |
double middleY = y + (Math.sin(angleMiddle) * 0.5 + 0.5) * radius * 2; |
108 |
end = new Point3D(middleX, middleY, ((Point3D) center).getZ());
|
109 |
} |
110 |
|
111 |
/*
|
112 |
* (non-Javadoc)
|
113 |
*
|
114 |
* @see org.gvsig.fmap.geom.primitive.Arc#getCenterPoint()
|
115 |
*/
|
116 |
public Point getCenterPoint() { |
117 |
((PointJTS) init).getJTS(); |
118 |
Point3D center = new Point3D(JTSUtils.getCircumcentre(init, middle, end));
|
119 |
return center;
|
120 |
} |
121 |
|
122 |
/*
|
123 |
* (non-Javadoc)
|
124 |
*
|
125 |
* @see org.gvsig.fmap.geom.Geometry#cloneGeometry()
|
126 |
*/
|
127 |
public Geometry cloneGeometry() {
|
128 |
Arc2DZ arc2D = new Arc2DZ();
|
129 |
arc2D.setPoints(init, middle, end); |
130 |
return arc2D;
|
131 |
} |
132 |
|
133 |
/*
|
134 |
* (non-Javadoc)
|
135 |
*
|
136 |
* @see
|
137 |
* org.gvsig.fmap.geom.jts.primitive.curve.line.AbstractLine#fixPoint(org
|
138 |
* .gvsig.fmap.geom.primitive.Point)
|
139 |
*/
|
140 |
@Override
|
141 |
protected Point fixPoint(Point point) { |
142 |
if (point instanceof Point3D) { |
143 |
Point3D point3D = (Point3D) point; |
144 |
if (Double.isNaN(zValue) && !(Double.isNaN(point3D.getZ()))) { |
145 |
zValue = point3D.getZ(); |
146 |
if (init!=null) { |
147 |
((Point3D) init).setZ(zValue); |
148 |
} |
149 |
if (middle!=null) { |
150 |
((Point3D) middle).setZ(zValue); |
151 |
} |
152 |
if (end!=null) { |
153 |
((Point3D) end).setZ(zValue); |
154 |
} |
155 |
return point3D;
|
156 |
} |
157 |
} |
158 |
return new Point3D(point.getX(), point.getY(), Double.isNaN(zValue)?0:zValue); |
159 |
} |
160 |
|
161 |
/*
|
162 |
* (non-Javadoc)
|
163 |
*
|
164 |
* @see org.gvsig.fmap.geom.jts.GeometryJTS#getJTS()
|
165 |
*/
|
166 |
public com.vividsolutions.jts.geom.Geometry getJTS() {
|
167 |
PathIterator pi = getPathIterator(null); |
168 |
ArrayListCoordinateSequence coordinates = new ArrayListCoordinateSequence();
|
169 |
|
170 |
double coords[] = new double[6]; |
171 |
while (!pi.isDone()) {
|
172 |
switch (pi.currentSegment(coords)) {
|
173 |
case PathIterator.SEG_MOVETO: |
174 |
coordinates.add(new Coordinate(coords[0], coords[1], zValue)); |
175 |
break;
|
176 |
case PathIterator.SEG_LINETO: |
177 |
coordinates.add(new Coordinate(coords[0], coords[1], zValue)); |
178 |
break;
|
179 |
case PathIterator.SEG_QUADTO: |
180 |
coordinates.add(new Coordinate(coords[0], coords[1], zValue)); |
181 |
coordinates.add(new Coordinate(coords[2], coords[3], zValue)); |
182 |
break;
|
183 |
case PathIterator.SEG_CUBICTO: |
184 |
coordinates.add(new Coordinate(coords[0], coords[1], zValue)); |
185 |
coordinates.add(new Coordinate(coords[2], coords[3], zValue)); |
186 |
coordinates.add(new Coordinate(coords[4], coords[5], zValue)); |
187 |
break;
|
188 |
case PathIterator.SEG_CLOSE: |
189 |
coordinates.add(coordinates.get(0));
|
190 |
break;
|
191 |
} |
192 |
pi.next(); |
193 |
} |
194 |
return JTSUtils.createJTSLinearRing(coordinates);
|
195 |
} |
196 |
} |