1 package org.opentrafficsim.core.geometry; 2 3 import org.djutils.draw.point.Point2d; 4 5 /** 6 * Line representation that a {@code Flattener} can flatten in to a polyline. 7 * <p> 8 * Copyright (c) 2023-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br> 9 * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>. 10 * </p> 11 * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a> 12 * @author <a href="https://tudelft.nl/staff/p.knoppers-1">Peter Knoppers</a> 13 * @author <a href="https://github.com/wjschakel">Wouter Schakel</a> 14 */ 15 public interface FlattableLine 16 { 17 18 /** 19 * Returns the point at the given fraction. The fraction may represent any parameter, such as <i>t</i> in a Bezier, <i>s</i> 20 * in a Clothoid, or simply the fraction of length. 21 * @param fraction double; fraction. 22 * @return double; point at the given fraction. 23 */ 24 Point2d get(double fraction); 25 26 /** 27 * Returns the direction at the given fraction. The fraction may represent any parameter, such as <i>t</i> in a Bezier, 28 * <i>s</i> in a Clothoid, or simply the fraction of length. The default implementation performs a numerical approach by 29 * looking at the direction between the points at fraction, and a point 1e-6 away. 30 * @param fraction double; fraction. 31 * @return double; direction at the given fraction. 32 */ 33 default double getDirection(final double fraction) 34 { 35 Point2d p1, p2; 36 if (fraction < 0.5) // to prevent going above 1.0 37 { 38 p1 = get(fraction); 39 p2 = get(fraction + 1e-6); 40 } 41 else 42 { 43 p1 = get(fraction - 1e-6); 44 p2 = get(fraction); 45 } 46 return p1.directionTo(p2); 47 } 48 49 }