1 package org.opentrafficsim.core.geometry;
2
3 import org.djunits.value.vdouble.scalar.Direction;
4 import org.djutils.draw.line.PolyLine2d;
5 import org.djutils.draw.point.OrientedPoint2d;
6
7 /**
8 * A continuous line defines a line in an exact manner, from which numerical polylines can be derived. The continuous definition
9 * is useful to accurately connect different lines, e.g. based on the direction of the point where they meet. Moreover, this
10 * direction may be accurately be determined by either of the lines. For example, an arc can be defined up to a certain angle.
11 * Whatever the angle of the last line segment in a polyline for the arc may be, the continuous line contains the final
12 * direction exactly. The continuous definition is also useful to define accurate offset lines, which depend on accurate
13 * directions especially at the line end points.
14 * <p>
15 * Copyright (c) 2023-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
16 * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
17 * </p>
18 * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
19 */
20 public interface ContinuousLine
21 {
22
23 /**
24 * Start point.
25 * @return OrientedPoint2d; start point.
26 */
27 OrientedPoint2d getStartPoint();
28
29 /**
30 * End point.
31 * @return OrientedPoint2d; end point.
32 */
33 OrientedPoint2d getEndPoint();
34
35 /**
36 * Start direction.
37 * @return Direction; start point.
38 */
39 default Direction getStartDirection()
40 {
41 return Direction.instantiateSI(getStartPoint().dirZ);
42 }
43
44 /**
45 * End direction.
46 * @return Direction; end point.
47 */
48 default Direction getEndDirection()
49 {
50 return Direction.instantiateSI(getEndPoint().dirZ);
51 }
52
53 /**
54 * Start curvature.
55 * @return double; start curvature.
56 */
57 double getStartCurvature();
58
59 /**
60 * End curvature.
61 * @return double; end curvature.
62 */
63 double getEndCurvature();
64
65 /**
66 * Start radius.
67 * @return double; start radius.
68 */
69 default double getStartRadius()
70 {
71 return 1.0 / getStartCurvature();
72 }
73
74 /**
75 * End radius.
76 * @return double; end radius.
77 */
78 default double getEndRadius()
79 {
80 return 1.0 / getEndCurvature();
81 }
82
83 /**
84 * Flatten continuous line in to a polyline. Implementations should use the flattener when relevant and possible.
85 * @param flattener Flattener; flattener.
86 * @return PolyLine2d; flattened line.
87 */
88 PolyLine2d flatten(Flattener flattener);
89
90 /**
91 * Flatten continuous line offset in to a polyline. Implementations should use the flattener when relevant and possible.
92 * @param offsets FractionalLengthData; offset data.
93 * @param flattener Flattener; flattener.
94 * @return PolyLine2d; flattened line.
95 */
96 PolyLine2d flattenOffset(FractionalLengthData offsets, Flattener flattener);
97
98 /**
99 * Return the length of the line.
100 * @return double; length of the line.
101 */
102 double getLength();
103
104 }