1
2
3
4
5 package math.geom2d.line;
6
7 import java.util.Iterator;
8
9 import math.geom2d.Angle2D;
10 import math.geom2d.Point2D;
11 import math.geom2d.conic.Circle2D;
12 import math.geom2d.conic.CircleArc2D;
13 import math.geom2d.domain.BoundaryPolyCurve2D;
14 import math.geom2d.domain.PolyOrientedCurve2D;
15 import math.geom2d.domain.SmoothOrientedCurve2D;
16
17
18
19
20
21
22
23
24 @Deprecated
25 public abstract class Polyline2DUtils {
26
27
28
29
30
31
32
33
34
35
36 public final static PolyOrientedCurve2D<SmoothOrientedCurve2D> createParallel(
37 math.geom2d.polygon.Polyline2D polyline, double d) {
38
39
40 PolyOrientedCurve2D<SmoothOrientedCurve2D> result = new PolyOrientedCurve2D<SmoothOrientedCurve2D>();
41 result.setClosed(polyline instanceof ClosedPolyline2D);
42
43
44 if (polyline.getVertices().size()<2)
45 return result;
46
47
48
49
50 Point2D v1, v2;
51
52
53
54 Point2D p1, p2, p0 = null;
55
56
57 StraightLine2D line0, line;
58
59
60 Circle2D circle;
61
62 Iterator<Point2D> iterator;
63
64
65
66 if (polyline instanceof ClosedPolyline2D) {
67
68
69
70 LineSegment2D lastEdge = polyline.getLastEdge();
71 line0 = StraightLine2D.createParallel(lastEdge, d);
72
73 v2 = lastEdge.getLastPoint();
74 p0 = line0.getProjectedPoint(v2);
75
76
77 iterator = polyline.getVertices().iterator();
78 v1 = iterator.next();
79 v2 = iterator.next();
80 line = new StraightLine2D(v1, v2).getParallel(d);
81
82
83 p1 = line.getProjectedPoint(v1);
84 if (Angle2D.getAngle(line0, line)>Math.PI^d<0) {
85
86
87 p1 = line.getIntersection(line0);
88 p0 = p1;
89 } else {
90
91 circle = new Circle2D(v1, Math.abs(d));
92 result.addCurve(new CircleArc2D(v1, Math.abs(d), circle
93 .getPosition(p0), circle.getPosition(p1), d>0));
94 }
95
96 p2 = line.getProjectedPoint(v2);
97 line0 = line;
98 } else {
99
100 iterator = polyline.getVertices().iterator();
101 v1 = iterator.next();
102 v2 = iterator.next();
103
104
105 line0 = new StraightLine2D(v1, v2).getParallel(d);
106 p1 = line0.getProjectedPoint(v1);
107 p2 = line0.getProjectedPoint(v2);
108 }
109
110
111
112
113 while (iterator.hasNext()) {
114
115 v1 = v2;
116 v2 = iterator.next();
117 line = new StraightLine2D(v1, v2).getParallel(d);
118
119
120 if (Angle2D.getAngle(line0, line)>Math.PI^d<0) {
121
122
123 p2 = line.getIntersection(line0);
124 result.addCurve(new LineSegment2D(p1, p2));
125 p1 = p2;
126 } else {
127
128
129 result.addCurve(new LineSegment2D(p1, p2));
130 p1 = line.getProjectedPoint(v1);
131 circle = new Circle2D(v1, Math.abs(d));
132 result.addCurve(new CircleArc2D(v1, Math.abs(d), circle
133 .getPosition(p2), circle.getPosition(p1), d>0));
134 }
135
136
137 p2 = line.getProjectedPoint(v2);
138 line0 = line;
139 }
140
141
142
143 if (polyline instanceof ClosedPolyline2D) {
144
145 iterator = polyline.getVertices().iterator();
146 v1 = v2;
147 v2 = iterator.next();
148 line = new StraightLine2D(v1, v2).getParallel(d);
149
150
151 if (Angle2D.getAngle(line0, line)>Math.PI^d<0) {
152
153
154 p2 = line.getIntersection(line0);
155 result.addCurve(new LineSegment2D(p1, p2));
156 p1 = p2;
157 } else {
158
159
160 result.addCurve(new LineSegment2D(p1, p2));
161 p1 = line.getProjectedPoint(v1);
162 circle = new Circle2D(v1, Math.abs(d));
163 result.addCurve(new CircleArc2D(v1, Math.abs(d), circle
164 .getPosition(p2), circle.getPosition(p1), d>0));
165 }
166
167
168 result.addCurve(new LineSegment2D(p1, p0));
169 } else {
170
171 result.addCurve(new LineSegment2D(p1, p2));
172 }
173
174
175 return result;
176 }
177
178
179
180
181
182
183
184
185
186
187 public final static BoundaryPolyCurve2D<SmoothOrientedCurve2D> createClosedParallel(
188 ClosedPolyline2D polyline, double d) {
189
190
191 BoundaryPolyCurve2D<SmoothOrientedCurve2D> result = new BoundaryPolyCurve2D<SmoothOrientedCurve2D>();
192 result.setClosed(true);
193
194
195 if (polyline.getVertices().size()<2)
196 return result;
197
198
199
200
201 Point2D v1, v2;
202
203
204
205 Point2D p1, p2, p0 = null;
206
207
208 StraightLine2D line0, line;
209
210
211 Circle2D circle;
212
213 Iterator<Point2D> iterator;
214
215
216
217
218
219
220 LineSegment2D lastEdge = polyline.getLastEdge();
221 line0 = StraightLine2D.createParallel(lastEdge, d);
222
223 v2 = lastEdge.getLastPoint();
224 p0 = line0.getProjectedPoint(v2);
225
226
227 iterator = polyline.getVertices().iterator();
228 v1 = iterator.next();
229 v2 = iterator.next();
230 line = new StraightLine2D(v1, v2).getParallel(d);
231
232
233 p1 = line.getProjectedPoint(v1);
234 if (Angle2D.getAngle(line0, line)>Math.PI^d<0) {
235
236
237 p1 = line.getIntersection(line0);
238 p0 = p1;
239 } else {
240
241 circle = new Circle2D(v1, Math.abs(d));
242 result.addCurve(new CircleArc2D(v1, Math.abs(d), circle
243 .getPosition(p0), circle.getPosition(p1), d>0));
244 }
245
246 p2 = line.getProjectedPoint(v2);
247 line0 = line;
248
249
250
251
252 while (iterator.hasNext()) {
253
254 v1 = v2;
255 v2 = iterator.next();
256 line = new StraightLine2D(v1, v2).getParallel(d);
257
258
259 if (Angle2D.getAngle(line0, line)>Math.PI^d<0) {
260
261
262 p2 = line.getIntersection(line0);
263 result.addCurve(new LineSegment2D(p1, p2));
264 p1 = p2;
265 } else {
266
267
268 result.addCurve(new LineSegment2D(p1, p2));
269 p1 = line.getProjectedPoint(v1);
270 circle = new Circle2D(v1, Math.abs(d));
271 result.addCurve(new CircleArc2D(v1, Math.abs(d), circle
272 .getPosition(p2), circle.getPosition(p1), d>0));
273 }
274
275
276 p2 = line.getProjectedPoint(v2);
277 line0 = line;
278 }
279
280
281
282
283 iterator = polyline.getVertices().iterator();
284 v1 = v2;
285 v2 = iterator.next();
286 line = new StraightLine2D(v1, v2).getParallel(d);
287
288
289 if (Angle2D.getAngle(line0, line)>Math.PI^d<0) {
290
291
292 p2 = line.getIntersection(line0);
293 result.addCurve(new LineSegment2D(p1, p2));
294 p1 = p2;
295 } else {
296
297
298 result.addCurve(new LineSegment2D(p1, p2));
299 p1 = line.getProjectedPoint(v1);
300 circle = new Circle2D(v1, Math.abs(d));
301 result.addCurve(new CircleArc2D(v1, Math.abs(d), circle
302 .getPosition(p2), circle.getPosition(p1), d>0));
303 }
304
305
306 result.addCurve(new LineSegment2D(p1, p0));
307
308
309 return result;
310 }
311 }