ContinuousLine.java

  1. package org.opentrafficsim.core.geometry;

  2. import java.util.function.Function;

  3. import org.djunits.value.vdouble.scalar.Direction;
  4. import org.djutils.draw.line.PolyLine2d;
  5. import org.djutils.draw.point.OrientedPoint2d;

  6. /**
  7.  * A continuous line defines a line in an exact manner, from which numerical polylines can be derived. The continuous definition
  8.  * is useful to accurately connect different lines, e.g. based on the direction of the point where they meet. Moreover, this
  9.  * direction may be accurately be determined by either of the lines. For example, an arc can be defined up to a certain angle.
  10.  * Whatever the angle of the last line segment in a polyline for the arc may be, the continuous line contains the final
  11.  * direction exactly. The continuous definition is also useful to define accurate offset lines, which depend on accurate
  12.  * directions especially at the line end points.
  13.  * <p>
  14.  * Copyright (c) 2023-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
  15.  * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
  16.  * </p>
  17.  * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
  18.  */
  19. public interface ContinuousLine
  20. {

  21.     /**
  22.      * Start point.
  23.      * @return start point
  24.      */
  25.     OrientedPoint2d getStartPoint();

  26.     /**
  27.      * End point.
  28.      * @return end point
  29.      */
  30.     OrientedPoint2d getEndPoint();

  31.     /**
  32.      * Start direction.
  33.      * @return start point
  34.      */
  35.     default Direction getStartDirection()
  36.     {
  37.         return Direction.instantiateSI(getStartPoint().dirZ);
  38.     }

  39.     /**
  40.      * End direction.
  41.      * @return end point
  42.      */
  43.     default Direction getEndDirection()
  44.     {
  45.         return Direction.instantiateSI(getEndPoint().dirZ);
  46.     }

  47.     /**
  48.      * Start curvature.
  49.      * @return start curvature
  50.      */
  51.     double getStartCurvature();

  52.     /**
  53.      * End curvature.
  54.      * @return end curvature
  55.      */
  56.     double getEndCurvature();

  57.     /**
  58.      * Start radius.
  59.      * @return start radius
  60.      */
  61.     default double getStartRadius()
  62.     {
  63.         return 1.0 / getStartCurvature();
  64.     }

  65.     /**
  66.      * End radius.
  67.      * @return end radius
  68.      */
  69.     default double getEndRadius()
  70.     {
  71.         return 1.0 / getEndCurvature();
  72.     }

  73.     /**
  74.      * Flatten continuous line in to a polyline. Implementations should use the flattener when relevant and possible.
  75.      * @param flattener flattener
  76.      * @return flattened line
  77.      */
  78.     PolyLine2d flatten(Flattener flattener);

  79.     /**
  80.      * Flatten continuous line offset in to a polyline. Implementations should use the flattener when relevant and possible.
  81.      * @param offset offset data
  82.      * @param flattener flattener
  83.      * @return flattened line
  84.      */
  85.     PolyLine2d flattenOffset(ContinuousDoubleFunction offset, Flattener flattener);

  86.     /**
  87.      * Return the length of the line.
  88.      * @return length of the line
  89.      */
  90.     double getLength();

  91.     /**
  92.      * Temporary function implementation with {@code getDerivative()} and {@code getKnots()} method.
  93.      */
  94.     interface ContinuousDoubleFunction extends Function<Double, Double>
  95.     {
  96.         /**
  97.          * Returns the derivative of the data with respect to fractional length.
  98.          * @param fractionalLength fractional length, may be outside range [0 ... 1]
  99.          * @return derivative of the data with respect to fractional length
  100.          */
  101.         double getDerivative(double fractionalLength);

  102.         /**
  103.          * Returns knots in the function.
  104.          * @return knots in the function
  105.          */
  106.         double[] getKnots();
  107.     }
  108. }