Class Plane


  • public final class Plane
    extends java.lang.Object
    Represents a Plane in Cartesian coordinates, defined by a normal vector to the plane and a signed scalar value proportional to the distance of the plane from the origin. The sign of the value is relative to the direction of the plane normal.
    • Constructor Summary

      Constructors 
      Constructor Description
      Plane​(double nx, double ny, double nz, double d)
      Constructs a plane from four values giving the plane normal vector and distance.
      Plane​(Vec4 vec)
      Constructs a plane from a 4-D vector giving the plane normal vector and distance.
    • Constructor Detail

      • Plane

        public Plane​(Vec4 vec)
        Constructs a plane from a 4-D vector giving the plane normal vector and distance.
        Parameters:
        vec - a 4-D vector indicating the plane's normal vector and distance. The normal need not be unit length.
        Throws:
        java.lang.IllegalArgumentException - if the vector is null.
      • Plane

        public Plane​(double nx,
                     double ny,
                     double nz,
                     double d)
        Constructs a plane from four values giving the plane normal vector and distance.
        Parameters:
        nx - the X component of the plane normal vector.
        ny - the Y component of the plane normal vector.
        nz - the Z component of the plane normal vector.
        d - the plane distance.
        Throws:
        java.lang.IllegalArgumentException - if the normal vector components define the zero vector (all values are zero).
    • Method Detail

      • fromPoints

        public static Plane fromPoints​(Vec4 pa,
                                       Vec4 pb,
                                       Vec4 pc)
        Returns the plane that passes through the specified three points. The plane's normal is the cross product of the two vectors from pb to pa and pc to pa, respectively. The returned plane is undefined if any of the specified points are colinear.
        Parameters:
        pa - the first point.
        pb - the second point.
        pc - the third point.
        Returns:
        a Plane passing through the specified points.
        Throws:
        java.lang.IllegalArgumentException - if pa, pb, or pc is null.
      • getNormal

        public final Vec4 getNormal()
        Returns the plane's normal vector.
        Returns:
        the plane's normal vector.
      • getDistance

        public final double getDistance()
        Returns the plane distance.
        Returns:
        the plane distance.
      • getVector

        public final Vec4 getVector()
        Returns a 4-D vector holding the plane's normal and distance.
        Returns:
        a 4-D vector indicating the plane's normal vector and distance.
      • normalize

        public final Plane normalize()
        Returns a normalized version of this plane. The normalized plane's normal vector is unit length and its distance is D/|N| where |N| is the length of this plane's normal vector.
        Returns:
        a normalized copy of this Plane.
      • dot

        public final double dot​(Vec4 p)
        Calculates the 4-D dot product of this plane with a vector.
        Parameters:
        p - the vector.
        Returns:
        the dot product of the plane and the vector.
        Throws:
        java.lang.IllegalArgumentException - if the vector is null.
      • intersect

        public Vec4 intersect​(Line line)
        Determine the intersection point of a line with this plane.
        Parameters:
        line - the line to intersect.
        Returns:
        the intersection point if the line intersects the plane, otherwise null.
        Throws:
        java.lang.IllegalArgumentException - if the line is null.
      • intersectDistance

        public double intersectDistance​(Line line)
        Determine the parametric point of intersection of a line with this plane.
        Parameters:
        line - the line to test
        Returns:
        The parametric value of the point on the line at which it intersects the plane. Double.NaN is returned if the line does not intersect the plane. Double.POSITIVE_INFINITY is returned if the line is coincident with the plane.
        Throws:
        java.lang.IllegalArgumentException - if the line is null.
      • intersect

        public Vec4 intersect​(Vec4 pa,
                              Vec4 pb)
        Test a line segment for intersection with this plane. If it intersects, return the point of intersection.
        Parameters:
        pa - the first point of the line segment.
        pb - the second point of the line segment.
        Returns:
        The point of intersection with the plane. Null is returned if the segment does not instersect this plane. Vec4.INFINITY coincident with the plane.
        Throws:
        java.lang.IllegalArgumentException - if either input point is null.
      • clip

        public Vec4[] clip​(Vec4 pa,
                           Vec4 pb)
        Clip a line segment to this plane.
        Parameters:
        pa - the first point of the segment.
        pb - the second point of the segment.
        Returns:
        An array of two points both on the positive side of the plane. If the direction of the line formed by the two points is positive with respect to this plane's normal vector, the first point in the array will be the intersection point on the plane, and the second point will be the original segment end point. If the direction of the line is negative with respect to this plane's normal vector, the first point in the array will be the original segment's begin point, and the second point will be the intersection point on the plane. If the segment does not intersect the plane, null is returned. If the segment is coincident with the plane, the input points are returned, in their input order.
        Throws:
        java.lang.IllegalArgumentException - if either input point is null.
      • distanceTo

        public double distanceTo​(Vec4 p)
      • onSameSide

        public int onSameSide​(Vec4 pa,
                              Vec4 pb)
        Determines whether two points are on the same side of a plane.
        Parameters:
        pa - the first point.
        pb - the second point.
        Returns:
        true if the points are on the same side of the plane, otherwise false.
        Throws:
        java.lang.IllegalArgumentException - if either point is null.
      • onSameSide

        public int onSameSide​(Vec4[] pts)
        Determines whether multiple points are on the same side of a plane.
        Parameters:
        pts - the array of points.
        Returns:
        true if the points are on the same side of the plane, otherwise false.
        Throws:
        java.lang.IllegalArgumentException - if the points array is null or any point within it is null.
      • intersect

        public static Vec4 intersect​(Plane pa,
                                     Plane pb,
                                     Plane pc)
        Compute the intersection of three planes.
        Parameters:
        pa - the first plane.
        pb - the second plane.
        pc - the third plane.
        Returns:
        the Cartesian coordinates of the intersection, or null if the three planes to not intersect at a point.
        Throws:
        java.lang.IllegalArgumentException - if any of the planes are null.
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

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

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