Class OTSPoint3D

java.lang.Object
org.opentrafficsim.core.geometry.OTSPoint3D
All Implemented Interfaces:
java.io.Serializable, Locatable

public class OTSPoint3D
extends java.lang.Object
implements Locatable, java.io.Serializable
An OTSPoint3D implements a 3D-coordinate for OTS. X, y and z are stored as doubles, but it is assumed that the scale is in SI units, i.e. in meters. A distance between two points is therefore also in meters.

Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See OpenTrafficSim License.

$LastChangedDate: 2015-07-16 10:20:53 +0200 (Thu, 16 Jul 2015) $, @version $Revision: 1124 $, by $Author: pknoppers $, initial version Jul 22, 2015

Author:
Alexander Verbraeck, Peter Knoppers, Guus Tamminga
See Also:
Serialized Form
  • Field Details

    • x

      public final double x
      The internal representation of the point; x-coordinate.
    • y

      public final double y
      The internal representation of the point; y-coordinate.
    • z

      public final double z
      The internal representation of the point; z-coordinate.
  • Constructor Details

    • OTSPoint3D

      public OTSPoint3D​(double x, double y, double z)
      The x, y and z in the point are assumed to be in meters relative to an origin.
      Parameters:
      x - double; x-coordinate
      y - double; y-coordinate
      z - double; z-coordinate
    • OTSPoint3D

      public OTSPoint3D​(double[] xyz)
      Parameters:
      xyz - array with three elements; x, y and z are assumed to be in meters relative to an origin.
    • OTSPoint3D

      public OTSPoint3D​(OTSPoint3D point)
      Parameters:
      point - OTSPoint3D; a point to "clone".
    • OTSPoint3D

      public OTSPoint3D​(javax.vecmath.Point3d point)
      Parameters:
      point - javax.vecmath 3D double point; the x, y and z in the point are assumed to be in meters relative to an origin.
    • OTSPoint3D

      public OTSPoint3D​(CartesianPoint point)
      Parameters:
      point - javax.vecmath 3D double point; the x, y and z in the point are assumed to be in meters relative to an origin.
    • OTSPoint3D

      public OTSPoint3D​(DirectedPoint point)
      Parameters:
      point - javax.vecmath 3D double point; the x, y and z in the point are assumed to be in meters relative to an origin.
    • OTSPoint3D

      public OTSPoint3D​(java.awt.geom.Point2D point2d)
      Parameters:
      point2d - java.awt 2D point, z-coordinate will be zero; the x and y in the point are assumed to be in meters relative to an origin.
    • OTSPoint3D

      public OTSPoint3D​(org.locationtech.jts.geom.Coordinate coordinate)
      Parameters:
      coordinate - geotools coordinate; the x, y and z in the coordinate are assumed to be in meters relative to an origin.
    • OTSPoint3D

      public OTSPoint3D​(org.locationtech.jts.geom.Point point)
      Parameters:
      point - geotools point; z-coordinate will be zero; the x and y in the point are assumed to be in meters relative to an origin.
    • OTSPoint3D

      public OTSPoint3D​(double x, double y)
      The x and y in the point are assumed to be in meters relative to an origin. z will be set to 0.
      Parameters:
      x - double; x-coordinate
      y - double; y-coordinate
  • Method Details

    • interpolate

      public static OTSPoint3D interpolate​(double ratio, OTSPoint3D zeroValue, OTSPoint3D oneValue)
      Interpolate (or extrapolate) between (outside) two given points.
      Parameters:
      ratio - double; 0 selects the zeroValue point, 1 selects the oneValue point, 0.5 selects a point halfway, etc.
      zeroValue - OTSPoint3D; the point that is returned when ratio equals 0
      oneValue - OTSPoint3D; the point that is returned when ratio equals 1
      Returns:
      OTSPoint3D
    • intersectionOfLineSegmentsDumb

      @Deprecated public static OTSPoint3D intersectionOfLineSegmentsDumb​(OTSPoint3D line1P1, OTSPoint3D line1P2, OTSPoint3D line2P1, OTSPoint3D line2P2)
      Deprecated.
      Compute the 2D intersection of two line segments. The Z-component of the lines is ignored. Both line segments are defined by two points (that should be distinct). This version suffers loss of precision when called with very large coordinate values.
      Parameters:
      line1P1 - OTSPoint3D; first point of line segment 1
      line1P2 - OTSPoint3D; second point of line segment 1
      line2P1 - OTSPoint3D; first point of line segment 2
      line2P2 - OTSPoint3D; second point of line segment 2
      Returns:
      OTSPoint3D; the intersection of the two lines, or null if the lines are (almost) parallel, or do not intersect
    • intersectionOfLineSegments

      public static OTSPoint3D intersectionOfLineSegments​(OTSPoint3D line1P1, OTSPoint3D line1P2, OTSPoint3D line2P1, OTSPoint3D line2P2)
      Compute the 2D intersection of two line segments. The Z-component of the lines is ignored. Both line segments are defined by two points (that should be distinct).
      Parameters:
      line1P1 - OTSPoint3D; first point of line segment 1
      line1P2 - OTSPoint3D; second point of line segment 1
      line2P1 - OTSPoint3D; first point of line segment 2
      line2P2 - OTSPoint3D; second point of line segment 2
      Returns:
      OTSPoint3D; the intersection of the two lines, or null if the lines are (almost) parallel, or do not intersect
    • intersectionOfLinesDumb

      @Deprecated public static OTSPoint3D intersectionOfLinesDumb​(OTSPoint3D line1P1, OTSPoint3D line1P2, OTSPoint3D line2P1, OTSPoint3D line2P2)
      Deprecated.
      Compute the 2D intersection of two infinite lines. The Z-component of the lines is ignored. Both lines are defined by two points (that should be distinct). This version suffers loss of precision when called with very large coordinate values.
      Parameters:
      line1P1 - OTSPoint3D; first point of line 1
      line1P2 - OTSPoint3D; second point of line 1
      line2P1 - OTSPoint3D; first point of line 2
      line2P2 - OTSPoint3D; second point of line 2
      Returns:
      OTSPoint3D; the intersection of the two lines, or null if the lines are (almost) parallel
    • intersectionOfLines

      public static OTSPoint3D intersectionOfLines​(OTSPoint3D line1P1, OTSPoint3D line1P2, OTSPoint3D line2P1, OTSPoint3D line2P2)
      Compute the 2D intersection of two infinite lines. The Z-component of the lines is ignored. Both lines are defined by two points (that should be distinct).
      Parameters:
      line1P1 - OTSPoint3D; first point of line 1
      line1P2 - OTSPoint3D; second point of line 1
      line2P1 - OTSPoint3D; first point of line 2
      line2P2 - OTSPoint3D; second point of line 2
      Returns:
      OTSPoint3D; the intersection of the two lines, or null if the lines are (almost) parallel
    • closestPointOnSegment

      public final OTSPoint3D closestPointOnSegment​(OTSPoint3D segmentPoint1, OTSPoint3D segmentPoint2)
      Project a point on a line segment (2D - Z-component is ignored). If the the projected points lies outside the line segment, the nearest end point of the line segment is returned. Otherwise the returned point lies between the end points of the line segment.
      Adapted from example code provided by Paul Bourke.
      Parameters:
      segmentPoint1 - OTSPoint3D; start of line segment
      segmentPoint2 - OTSPoint3D; end of line segment
      Returns:
      Point2D.Double; either lineP1, or lineP2 or a new OTSPoint3D that lies somewhere in between those two. The Z-component of the result matches the Z-component of the line segment at that point
    • closestPointOnLine

      public final OTSPoint3D closestPointOnLine​(OTSLine3D line)
      Return the closest point on an OTSLine3D. This method takes the Z-component of this point and the line into account.
      Parameters:
      line - OTSLine3D; the line
      Returns:
      OTSPoint3D; the Z-component of the returned point matches the Z-component of the line at that point
    • closestPointOnLine2D

      public final OTSPoint3D closestPointOnLine2D​(OTSLine3D line)
      Return the closest point on an OTSLine3D. This method ignores the Z-component of this point and the line when computing the distance.
      Parameters:
      line - OTSLine3D; the line
      Returns:
      OTSPoint3D; the Z-component of the returned point matches the Z-component of the line at that point
    • normalize

      public final OTSPoint3D normalize()
      Return the point with a length of 1 to the origin.
      Returns:
      OTSPoint3D; the normalized point
    • translate

      public final OTSPoint3D translate​(double factor)
      Return this point translated by a factor from the origin.
      Parameters:
      factor - double; the translation factor
      Returns:
      OTSPoint3D; the translated point
    • circleCenter

      public static final java.util.List<OTSPoint3D> circleCenter​(OTSPoint3D point1, OTSPoint3D point2, double radius)
      Return the possible center points of a circle (sphere), given two points and a radius. Only points with Z-coordinate equal to the mean of the given points are returned. (Without this restriction on the Z-coordinate, the result set would be either empty, a single point, or all points on a circle.)
      Parameters:
      point1 - OTSPoint3D; the first point
      point2 - OTSPoint3D; the second point
      radius - double; the radius
      Returns:
      List<OTSPoint3D> a list of zero, one or two points
    • circleIntersections

      public static final java.util.List<OTSPoint3D> circleIntersections​(OTSPoint3D center1, double radius1, OTSPoint3D center2, double radius2)
      Return the possible intersections between two circles.
      Parameters:
      center1 - OTSPoint3D; the center of circle 1
      radius1 - double; the radius of circle 1
      center2 - OTSPoint3D; the center of circle 2
      radius2 - double; the radius of circle 2
      Returns:
      List<OTSPoint3D> a list of zero, one or two points
    • distanceSI

      public final double distanceSI​(OTSPoint3D point)
      Parameters:
      point - OTSPoint3D; the point to which the distance has to be calculated.
      Returns:
      the distance in 3D according to Pythagoras, expressed in the SI unit for length (meter)
    • horizontalDistanceSI

      public final double horizontalDistanceSI​(OTSPoint3D point)
      Parameters:
      point - OTSPoint3D; the point to which the distance has to be calculated.
      Returns:
      the distance in 3D according to Pythagoras, expressed in the SI unit for length (meter)
    • horizontalDistance

      public final Length horizontalDistance​(OTSPoint3D point)
      Parameters:
      point - OTSPoint3D; the point to which the distance has to be calculated.
      Returns:
      the distance in 3D according to Pythagoras
    • distance

      public final Length distance​(OTSPoint3D point)
      Compute the distance to another point.
      Parameters:
      point - OTSPoint3D; the point to which the distance has to be calculated.
      Returns:
      the distance in 3D according to Pythagoras
    • horizontalDirectionSI

      public final double horizontalDirectionSI​(OTSPoint3D point)
      Compute the horizontal direction to another point.
      Parameters:
      point - OTSPoint3D; the other point
      Returns:
      double; the direction in radians
    • horizontalDirection

      public final Direction horizontalDirection​(OTSPoint3D point)
      Compute the horizontal direction to another point.
      Parameters:
      point - OTSPoint3D; the other point
      Returns:
      double; the direction in radians
    • getCoordinate

      public final org.locationtech.jts.geom.Coordinate getCoordinate()
      Returns:
      the equivalent geotools Coordinate of this point.
    • getDirectedPoint

      public final DirectedPoint getDirectedPoint()
      Returns:
      the equivalent DSOL DirectedPoint of this point. Should the result be cached?
    • getPoint2D

      public final java.awt.geom.Point2D getPoint2D()
      Returns:
      a Point2D with the x and y structure.
    • getLocation

      public final DirectedPoint getLocation()
      Specified by:
      getLocation in interface Locatable
    • getBounds

      public final javax.media.j3d.Bounds getBounds()
      This method returns a sphere with a diameter of half a meter as the default bounds for a point.
      Specified by:
      getBounds in interface Locatable
    • toString

      public java.lang.String toString()
      Overrides:
      toString in class java.lang.Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class java.lang.Object
    • equals

      public boolean equals​(java.lang.Object obj)
      Overrides:
      equals in class java.lang.Object