View Javadoc
1   package org.djutils.draw.curve;
2   
3   import org.djutils.draw.Direction3d;
4   import org.djutils.draw.curve.Flattener.FlattableCurve;
5   import org.djutils.draw.line.PolyLine3d;
6   import org.djutils.draw.point.DirectedPoint3d;
7   import org.djutils.draw.point.Point3d;
8   
9   /**
10   * This interface narrows down the interface of continuous curves for 3d use.
11   * <p>
12   * Copyright (c) 2023-2025 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
13   * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
14   * </p>
15   * @author <a href="https://www.tudelft.nl/averbraeck">Alexander Verbraeck</a>
16   * @author <a href="https://www.tudelft.nl/pknoppers">Peter Knoppers</a>
17   * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
18   */
19  interface Curve3d
20          extends Curve<DirectedPoint3d, Direction3d, Point3d, Flattener3d, PolyLine3d>, FlattableCurve<Point3d, Direction3d>
21  {
22  
23      @Override
24      default DirectedPoint3d getStartPoint()
25      {
26          return new DirectedPoint3d(getPoint(0.0), getDirection(0.0));
27      }
28  
29      @Override
30      default DirectedPoint3d getEndPoint()
31      {
32          return new DirectedPoint3d(getPoint(1.0), getDirection(1.0));
33      }
34  
35      @Override
36      default Direction3d getStartDirection()
37      {
38          return getStartPoint().getDir();
39      }
40  
41      @Override
42      default Direction3d getEndDirection()
43      {
44          return getEndPoint().getDir();
45      }
46  
47      @Override
48      default Direction3d getDirection(final double fraction)
49      {
50          Point3d p1, p2;
51          if (fraction < 0.5) // to prevent going above 1.0
52          {
53              p1 = getPoint(fraction);
54              p2 = getPoint(fraction + 1e-6);
55          }
56          else
57          {
58              p1 = getPoint(fraction - 1e-6);
59              p2 = getPoint(fraction);
60          }
61          return p1.directionTo(p2);
62      }
63  
64  }