Package edu.cnu.mdi.geometry
Class Plane
java.lang.Object
edu.cnu.mdi.geometry.Plane
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 -
Constructor Summary
ConstructorsConstructorDescriptionPlane(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 ofa*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.Creates a plane from a normal vector and a point on the plane. -
Method Summary
Modifier and TypeMethodDescriptionstatic PlaneconstantPhiPlane(double phi) Creates the vertical plane of constant azimuthal anglephi.doubledistance(double x, double y, double z) Computes the absolute distance from coordinates to the plane.doubleinterpolate(Point p1, Point p2, Point p) Creates a line through two points and computes the line-plane intersection.doublelineIntersection(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.intsign(double x, double y, double z) Computes the side of the plane on which coordinates lie.doublesignedDistance(double x, double y, double z) Computes the signed distance from coordinates to the plane.toString()Returns a string representation of this plane's coefficients.
-
Field Details
-
a
public final double aTheacoefficient ina*x + b*y + c*z = d. -
b
public final double bThebcoefficient ina*x + b*y + c*z = d. -
c
public final double cTheccoefficient ina*x + b*y + c*z = d. -
d
public final double dThedcoefficient ina*x + b*y + c*z = d.
-
-
Constructor Details
-
Plane
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 vectorp0- a point on the plane- Throws:
NullPointerException- if either argument isnullIllegalArgumentException- 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 ofa*x + b*y + c*z = d.- Parameters:
a- the x coefficientb- the y coefficientc- the z coefficientd- the right-hand side coefficient- Throws:
IllegalArgumentException- if a coefficient is non-finite, or ifa,b, andcare 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 componentsnx,ny, andnzpoint- an array containing point coordinatesx,y, andz- Throws:
NullPointerException- if either array isnullIndexOutOfBoundsException- if either array has fewer than three valuesIllegalArgumentException- 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 vectorny- y component of the normal vectornz- z component of the normal vectorpx- x coordinate of a point on the planepy- y coordinate of a point on the planepz- 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
Creates a line through two points and computes the line-plane intersection.- Parameters:
p1- one point defining the linep2- another point defining the linep- upon return, contains the intersection point; set to NaN components if the line is parallel to the plane- Returns:
- the line parameter
t;NaNmeans the line is parallel to the plane. If0 <= t <= 1, the finite segment intersects the plane. Iftis outside[0, 1], the infinite line intersects the plane but the finite segment does not. - Throws:
NullPointerException- if any point argument isnullIllegalArgumentException- ifp1andp2are 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 coordinatey- the y coordinatez- 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 coordinatey- the y coordinatez- the z coordinate- Returns:
- the signed distance; positive is the side pointed to by the normal
-
lineIntersection
Computes the intersection of an infinite line with this plane.- Parameters:
line- the line to intersect with this planeintersection- upon return, contains the intersection point; set to NaN components if the line is parallel to the plane- Returns:
- the line parameter
t;NaNmeans the line is parallel to the plane. If0 <= t <= 1, the finite segment intersects the plane. Iftis outside[0, 1], the infinite line intersects the plane but the finite segment does not. - Throws:
NullPointerException- if either argument isnull
-
sign
public int sign(double x, double y, double z) Computes the side of the plane on which coordinates lie.- Parameters:
x- the x coordinatey- the y coordinatez- the z coordinate- Returns:
+1ifa*x + b*y + c*z > d,-1if it is less thand, and0if it is exactly equal
-
constantPhiPlane
Creates the vertical plane of constant azimuthal anglephi.The angle is measured in degrees in the usual xy-plane sense:
phi = 0is the positive x axis andphi = 90is 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
Returns a string representation of this plane's coefficients. -
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
-