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