Interface Segment2d

All Known Subinterfaces:
MSegment2d

public interface Segment2d
Read-only interface for handling segments in the XY-plane.
Since:
9.10.2
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the point on this segment that is closest to the given point in the XY-plane.
    boolean
    contains​(Vector2d point)
    Returns true if the given point lies on this segment in the XY-plane, otherwise returns false.
    static Segment2d
    create​(Vector2d startPoint, Vector2d endPoint)
    Creates an new instance.
    double
    distance​(Vector2d point)
    Returns the minimum distance between this segment and the point in the XY-plane.
    double
    distance​(Segment2d other)
    Returns the minimum distance in the XY-plane between this and the given segment.
    double
    Returns the square of the minimum distance between this segment and the point in the XY-plane.
    double
    Returns the square of the minimum distance in the XY-plane between this and the given segment.
    default boolean
    equalsWithTolerance​(Segment2d other, double tolerance)
    Returns true if the start and end points of this segment are within tolerance of the start and end points of other in the XY-plane.
    Returns the end of the segment in the XY-plane.
    default double
    Returns the length of the segment in 2 dimensions.
    default double
    Returns the square of the length of the segment in 2 dimensions.
    Returns the beginning of the segment in the XY-plane.
    intersect​(Segment2d other)
    Returns the point of intersection between this segment and other in the XY-plane.
    default boolean
    Returns true if this segment and other intersect in the XY-plane, otherwise returns false.
    Returns a comparator that compares non-null Segments by their length in the XY-plane.
    default List<MVector2d>
    sample​(int amount)
    Samples the given amount of points from the segment.
    Returns the shortest segment from this segment to the given segment in the XY-plane.
  • Method Details

    • create

      static Segment2d create(Vector2d startPoint, Vector2d endPoint)
      Creates an new instance.
      Parameters:
      startPoint - the start point
      endPoint - the end point
      Returns:
      the newly created instance
      Since:
      9.10.2
    • getStartPoint

      Vector2d getStartPoint()
      Returns the beginning of the segment in the XY-plane.
      Returns:
      the beginning of the segment in the XY-plane
      Since:
      9.10.2
    • getEndPoint

      Vector2d getEndPoint()
      Returns the end of the segment in the XY-plane.
      Returns:
      the end of the segment in the XY-plane.
      Since:
      9.10.2
    • getLengthSquared

      default double getLengthSquared()
      Returns the square of the length of the segment in 2 dimensions.
      Returns:
      the square of the length of the segment in 2 dimensions
      Since:
      9.10.2
    • getLength

      default double getLength()
      Returns the length of the segment in 2 dimensions.
      Returns:
      the length of the segment in 2 dimensions
      Since:
      9.10.2
    • distanceSquared

      double distanceSquared(Vector2d point)
      Returns the square of the minimum distance between this segment and the point in the XY-plane.
      Parameters:
      point - the point to which the square of the distance is computed
      Returns:
      the square of the minimum distance between this segment and the point in the XY-plane
      Since:
      9.10.2
    • distance

      double distance(Vector2d point)
      Returns the minimum distance between this segment and the point in the XY-plane.
      Parameters:
      point - the point to which the distance is computed
      Returns:
      the minimum distance between this segment and the point in the XY-plane
      Since:
      9.10.2
    • closestPointTo

      MVector2d closestPointTo(Vector2d point)
      Returns the point on this segment that is closest to the given point in the XY-plane. The Z component of the returned vector is set to 0.
      Parameters:
      point - the point in the XY-plane for which the closest point on this Segment is computed
      Returns:
      the point on this segment that is closest to the given point in the XY-plane
      Since:
      9.10.2
    • distanceSquared

      double distanceSquared(Segment2d other)
      Returns the square of the minimum distance in the XY-plane between this and the given segment.
      Parameters:
      other - the segment to which the square of distance is computed
      Returns:
      the square of the minimum distance in the XY-plane between this and the given segment
      Since:
      9.10.2
    • distance

      double distance(Segment2d other)
      Returns the minimum distance in the XY-plane between this and the given segment.
      Parameters:
      other - the segment to which the distance is computed
      Returns:
      the minimum distance in the XY-plane between this and the given segment
      Since:
      9.10.2
    • intersects

      default boolean intersects(Segment2d other)
      Returns true if this segment and other intersect in the XY-plane, otherwise returns false.
      Parameters:
      other - the segment that is checked for intersection
      Returns:
      true if this segment and other intersect in the XY-plane, otherwise returns false
      Since:
      9.10.2
    • intersect

      Optional<MVector2d> intersect(Segment2d other)
      Returns the point of intersection between this segment and other in the XY-plane. If segments do not intersect returns null. The intersect(Segment2d) method can be used for checking if segments intersect. The returned vector has its Z component set to 0.
      Parameters:
      other - the segment with which the intersection point is computed
      Returns:
      an optional that contains the point of intersection between this segment and other in the XY-plane if it exists or an empty optional null if the segments do not intersect
      Since:
      9.10.2
    • contains

      boolean contains(Vector2d point)
      Returns true if the given point lies on this segment in the XY-plane, otherwise returns false.
      Parameters:
      point - the point that is checked for being located on this segment
      Returns:
      true if the given point lies on this segment in the XY-plane, otherwise returns false
      Since:
      9.10.2
    • sample

      default List<MVector2d> sample(int amount)
      Samples the given amount of points from the segment. The start and end point are not included in the sample. If an amount of zero or less is given, an empty list is returned.
      Parameters:
      amount - the amount of samples
      Returns:
      the samples as a list from start point towards the end point
    • equalsWithTolerance

      default boolean equalsWithTolerance(Segment2d other, double tolerance)
      Returns true if the start and end points of this segment are within tolerance of the start and end points of other in the XY-plane.
      Parameters:
      other - the segment that is checked for equality within tolerance
      tolerance - the allowed difference in distance between points
      Returns:
      true if the start and end points of this segment are within tolerance of the start and end points of other in the XY-plane
      Since:
      9.10.2
    • shortestSegmentBetween

      Segment2d shortestSegmentBetween(Segment2d segment)
      Returns the shortest segment from this segment to the given segment in the XY-plane. The returned Segment is not unique if the given Segment instances are parallel. If the segments intersect, then the ends of the returned segment will be equal.
      Parameters:
      segment - the target segment for the returned segment
      Returns:
      the shortest segment from this segment to the given segment
      Since:
      9.10.2
    • lengthComparator

      static Comparator<Segment2d> lengthComparator()
      Returns a comparator that compares non-null Segments by their length in the XY-plane. The longer segment is considered to be greater in the ordering defined by the comparator returned by this method. This can be used for sorting Segments by length.
      Returns:
      comparator that compares segments by length
      Since:
      9.10.2