Class Straight

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable

    public class Straight
    extends java.lang.Object
    implements java.lang.Cloneable, java.io.Serializable
    Represents a straight line within 2-dimensional Euclidean space.
    See Also:
    Serialized Form
    • Constructor Detail

      • Straight

        public Straight​(Line line)
        Constructs a new Straight through the start and end Point of the given Line.
        Parameters:
        line - the Line which the new Straight shall pass through
      • Straight

        public Straight​(Point point1,
                        Point point2)
        Constructs a new Straight that passes through the two given Points.
        Parameters:
        point1 - a first waypoint of the Straight to be constructed
        point2 - a second waypoint of the Straight to be constructed
    • Method Detail

      • getSignedDistanceCCW

        public static double getSignedDistanceCCW​(Point p,
                                                  Point q,
                                                  Point r)

        Computes the counter-clockwise (CCW) signed distance of the third Point to the Straight through the first two Point s.

        The CCW signed distance is positive if the three Points are in counter-clockwise order and negative if the Points are in clockwise order. It is zero if the third Point lies on the line.

        If the first two Points are equal to each other, this method returns the distance of the first Point to the last Point .

        Parameters:
        p - the start Point of the Straight
        q - the end Point of the Straight
        r - the relative Point
        Returns:
        the CCW signed distance of the Point r to the Straight through Points p and q
      • clone

        public Straight clone()
        Overrides:
        clone in class java.lang.Object
      • containsWithinSegment

        public boolean containsWithinSegment​(Vector segmentStart,
                                             Vector segmentEnd,
                                             Vector vector)
        Checks if the Point indicated by the provided Vector is a Point on the Straight segment between the given start and end Points indicated by their corresponding position Vectors.
        Parameters:
        segmentStart - A Vector indicating the start Point of the segment. It has to lie on this Straight.
        segmentEnd - A Vector indicating the end Point of the segment. It has to lie on this Straight.
        vector - The Vector that is checked for containment.
        Returns:
        true if the Point indicated by the given Vector lies on this Straight, within the specified segment, otherwise false
      • equals

        public boolean equals​(java.lang.Object other)
        Checks if this Straight is equal to the provided Straight . Two Straights s1 and s2 are equal, if the position Vector of s2 is a Point on s1 and the direction Vectors of s1 and s2 are parallel.
        Overrides:
        equals in class java.lang.Object
        See Also:
        Object.equals(java.lang.Object)
      • getIntersection

        public Vector getIntersection​(Straight other)
        Computes and returns the position Vector of the intersection of this Straight and the provided one. If the two Straights are parallel or identical, null is returned.
        Parameters:
        other - the Straight to compute the position Vector of the intersection with
        Returns:
        a Vector pointing to the intersection point, null if no intersection Point exists
      • getPositionVectorAt

        public Vector getPositionVectorAt​(double parameter)

        Returns the Vector on this Straight at the given parameter value. The Vector that you get is calculated by multiplying this Straight's direction Vector by the parameter value and translating that Vector by this Straight's position Vector.

        This method is the reverse of the getParameterAt(Vector) method.

        Parameters:
        parameter - the parameter value for which the corresponding Vector on this Straight is to be calculated
        Returns:
        the Vector on this Straight at the passed-in parameter value
      • getProjection

        public Vector getProjection​(Vector vector)
        Returns the projection of the given Vector onto this Straight, which is the Point on this Straight with the minimal distance to the Point, denoted by the provided Vector.
        Parameters:
        vector - the Vector whose projection should be determined
        Returns:
        a new Vector representing the projection of the provided Vector onto this Straight
      • getSignedDistanceCCW

        public double getSignedDistanceCCW​(Vector vector)

        Returns the counter-clockwise (CCW) signed distance of the given Vector to this Straight.

        The CCW signed distance indicates on which side of the Straight the Vector lies. If it lies on the right side of this Straight's direction Vector, the CCW signed distance is negative. If it is on the left side of this Straight's direction Vector, it is positive.

        Parameters:
        vector - the Vector for which the CCW signed distance to this Straight is to be calculated
        Returns:
        the CCW signed distance of the given Vector to this Straight
      • getSignedDistanceCW

        public double getSignedDistanceCW​(Vector vector)

        Returns the clockwise (CW) signed distance of the given Vector to this Straight.

        The CW signed distance indicates on which side of the Straight the Vector lies. If it is on the right side of this Straight's direction Vector, the CW signed distance is positive. If it is on the left side of this Straight's direction Vector, it is negative.

        Parameters:
        vector - the Vector for which the CW signed distance to this Straight is to be calculated
        Returns:
        the CW signed distance of the given Vector to this Straight
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
        See Also:
        Object.hashCode()
      • intersects

        public boolean intersects​(Straight other)
        Checks whether this Straight and the provided one have a single Point of intersection.
        Parameters:
        other - the Straight to test for an intersection Point with this Straight
        Returns:
        true if the two Straights intersect in one single Point, otherwise false
      • intersectsWithinSegment

        public boolean intersectsWithinSegment​(Vector segmentStart,
                                               Vector segmentEnd,
                                               Straight other)
        Checks whether this Straight and the provided one have an intersection Point which is inside the specified segment between the segmentStart and segmentEnd Vectors.
        Parameters:
        segmentStart - A Vector indicating the start Point of the segment. It has to be a Point on the Straight.
        segmentEnd - A Vector indicating the end Point of the segment. It has to be a Point on the Straight.
        other - The Straight to test.
        Returns:
        true if the two Straights intersect and the intersection Point is contained within the specified segment, otherwise false
      • isParallelTo

        public boolean isParallelTo​(Straight other)
        Checks if this Straight and the provided one are parallel to each other. Identical Straights are regarded to be parallel to each other.
        Parameters:
        other - the Straight that is checked to be parallel to this Straight
        Returns:
        true if the direction Vectors of this Straight and the provided one are parallel, otherwise false
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
        See Also:
        Object.toString()