Class Plane

java.lang.Object
edu.cnu.mdi.geometry.Plane

public class Plane extends Object
A plane in three-dimensional Cartesian space.

The plane is stored in the form a*x + b*y + c*z = d. It can also be viewed as (r - r0) dot n = 0, where r0 is a point on the plane and n = (a, b, c) is a normal vector. The sign of the signed distance is positive on the side pointed to by the normal.

Author:
heddle
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    final double
    The a coefficient in a*x + b*y + c*z = d.
    final double
    The b coefficient in a*x + b*y + c*z = d.
    final double
    The c coefficient in a*x + b*y + c*z = d.
    final double
    The d coefficient in a*x + b*y + c*z = d.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Plane(double[] norm, double[] point)
    Creates a plane from array-based normal and point values.
    Plane(double a, double b, double c, double d)
    Creates a plane from the coefficients of a*x + b*y + c*z = d.
    Plane(double nx, double ny, double nz, double px, double py, double pz)
    Creates a plane from a normal vector and a point on the plane.
    Plane(Vector anorm, Point p0)
    Creates a plane from a normal vector and a point on the plane.
  • Method Summary

    Modifier and Type
    Method
    Description
    static Plane
    constantPhiPlane(double phi)
    Creates the vertical plane of constant azimuthal angle phi.
    double
    distance(double x, double y, double z)
    Computes the absolute distance from coordinates to the plane.
    double
    Creates a line through two points and computes the line-plane intersection.
    double
    lineIntersection(Line line, Point intersection)
    Computes the intersection of an infinite line with this plane.
    float[]
    planeQuadCoordinates(float scale)
    Computes four vertices that can be used to draw a quadrilateral patch of this plane.
    int
    sign(double x, double y, double z)
    Computes the side of the plane on which coordinates lie.
    double
    signedDistance(double x, double y, double z)
    Computes the signed distance from coordinates to the plane.
    Returns a string representation of this plane's coefficients.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • a

      public final double a
      The a coefficient in a*x + b*y + c*z = d.
    • b

      public final double b
      The b coefficient in a*x + b*y + c*z = d.
    • c

      public final double c
      The c coefficient in a*x + b*y + c*z = d.
    • d

      public final double d
      The d coefficient in a*x + b*y + c*z = d.
  • Constructor Details

    • Plane

      public Plane(Vector anorm, Point p0)
      Creates a plane from a normal vector and a point on the plane.

      The stored normal is normalized to unit length.

      Parameters:
      anorm - the plane normal vector
      p0 - a point on the plane
      Throws:
      NullPointerException - if either argument is null
      IllegalArgumentException - if either argument contains non-finite values, or the normal is too close to zero to normalize
    • Plane

      public Plane(double a, double b, double c, double d)
      Creates a plane from the coefficients of a*x + b*y + c*z = d.
      Parameters:
      a - the x coefficient
      b - the y coefficient
      c - the z coefficient
      d - the right-hand side coefficient
      Throws:
      IllegalArgumentException - if a coefficient is non-finite, or if a, b, and c are all too close to zero to define a plane
    • Plane

      public Plane(double[] norm, double[] point)
      Creates a plane from array-based normal and point values.
      Parameters:
      norm - an array containing the normal components nx, ny, and nz
      point - an array containing point coordinates x, y, and z
      Throws:
      NullPointerException - if either array is null
      IndexOutOfBoundsException - if either array has fewer than three values
      IllegalArgumentException - if the normal vector is zero or too close to zero to normalize
    • Plane

      public Plane(double nx, double ny, double nz, double px, double py, double pz)
      Creates a plane from a normal vector and a point on the plane.
      Parameters:
      nx - x component of the normal vector
      ny - y component of the normal vector
      nz - z component of the normal vector
      px - x coordinate of a point on the plane
      py - y coordinate of a point on the plane
      pz - z coordinate of a point on the plane
      Throws:
      IllegalArgumentException - if the normal vector is zero or too close to zero to normalize
  • Method Details

    • interpolate

      public double interpolate(Point p1, Point p2, Point p)
      Creates a line through two points and computes the line-plane intersection.
      Parameters:
      p1 - one point defining the line
      p2 - another point defining the line
      p - upon return, contains the intersection point; set to NaN components if the line is parallel to the plane
      Returns:
      the line parameter t; NaN means the line is parallel to the plane. If 0 <= t <= 1, the finite segment intersects the plane. If t is outside [0, 1], the infinite line intersects the plane but the finite segment does not.
      Throws:
      NullPointerException - if any point argument is null
      IllegalArgumentException - if p1 and p2 are coincident or too close to define a stable line
    • distance

      public double distance(double x, double y, double z)
      Computes the absolute distance from coordinates to the plane.
      Parameters:
      x - the x coordinate
      y - the y coordinate
      z - the z coordinate
      Returns:
      the absolute distance to the plane
    • signedDistance

      public double signedDistance(double x, double y, double z)
      Computes the signed distance from coordinates to the plane.
      Parameters:
      x - the x coordinate
      y - the y coordinate
      z - the z coordinate
      Returns:
      the signed distance; positive is the side pointed to by the normal
    • lineIntersection

      public double lineIntersection(Line line, Point intersection)
      Computes the intersection of an infinite line with this plane.
      Parameters:
      line - the line to intersect with this plane
      intersection - upon return, contains the intersection point; set to NaN components if the line is parallel to the plane
      Returns:
      the line parameter t; NaN means the line is parallel to the plane. If 0 <= t <= 1, the finite segment intersects the plane. If t is outside [0, 1], the infinite line intersects the plane but the finite segment does not.
      Throws:
      NullPointerException - if either argument is null
    • sign

      public int sign(double x, double y, double z)
      Computes the side of the plane on which coordinates lie.
      Parameters:
      x - the x coordinate
      y - the y coordinate
      z - the z coordinate
      Returns:
      +1 if a*x + b*y + c*z > d, -1 if it is less than d, and 0 if it is exactly equal
    • constantPhiPlane

      public static Plane constantPhiPlane(double phi)
      Creates the vertical plane of constant azimuthal angle phi.

      The angle is measured in degrees in the usual xy-plane sense: phi = 0 is the positive x axis and phi = 90 is the positive y axis. The plane contains the z axis and the ray at the given azimuth.

      Parameters:
      phi - the azimuthal angle in degrees
      Returns:
      the plane of constant phi
    • toString

      public String toString()
      Returns a string representation of this plane's coefficients.
      Overrides:
      toString in class Object
      Returns:
      a string containing a, b, c, and d
    • planeQuadCoordinates

      public float[] planeQuadCoordinates(float scale)
      Computes four vertices that can be used to draw a quadrilateral patch of this plane.

      The returned array contains four xyz triples, suitable for JOGL-style vertex submission. The quadrilateral is not a mathematically bounded plane; it is a drawing convenience whose size is controlled by scale.

      Parameters:
      scale - a drawing scale, typically larger than the scene extent
      Returns:
      an array of twelve floats containing four xyz vertices