NASA World Wind

gov.nasa.worldwind.geom
Class Plane

java.lang.Object
  extended by gov.nasa.worldwind.geom.Plane

public final class Plane
extends 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
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.
 
Method Summary
 Vec4[] clip(Vec4 pa, Vec4 pb)
          Clip a line segment to this plane.
 double distanceTo(Vec4 p)
           
 double dot(Vec4 p)
          Calculates the 4-D dot product of this plane with a vector.
 boolean equals(Object o)
           
static Plane fromPoints(Vec4 pa, Vec4 pb, Vec4 pc)
          Returns the plane that passes through the specified three points.
 double getDistance()
          Returns the plane distance.
 Vec4 getNormal()
          Returns the plane's normal vector.
 Vec4 getVector()
          Returns a 4-D vector holding the plane's normal and distance.
 int hashCode()
           
 Vec4 intersect(Line line)
          Determine the intersection point of a line with this plane.
static Vec4 intersect(Plane pa, Plane pb, Plane pc)
          Compute the intersection of three planes.
 Vec4 intersect(Vec4 pa, Vec4 pb)
          Test a line segment for intersection with this plane.
 double intersectDistance(Line line)
          Determine the parametric point of intersection of a line with this plane.
 Plane normalize()
          Returns a normalized version of this plane.
 int onSameSide(Vec4[] pts)
          Determines whether multiple points are on the same side of a plane.
 int onSameSide(Vec4 pa, Vec4 pb)
          Determines whether two points are on the same side of a plane.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

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:
IllegalArgumentException - if the normal vector components define the zero vector (all values are zero).

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:
IllegalArgumentException - if the vector is null.
Method Detail

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:
IllegalArgumentException - if either input point is null.

distanceTo

public double distanceTo(Vec4 p)

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:
IllegalArgumentException - if the vector is null.

equals

public boolean equals(Object o)
Overrides:
equals in class Object

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:
IllegalArgumentException - if pa, pb, or pc is null.

getDistance

public final double getDistance()
Returns the plane distance.

Returns:
the plane distance.

getNormal

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

Returns:
the plane's normal vector.

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.

hashCode

public int hashCode()
Overrides:
hashCode in class Object

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:
IllegalArgumentException - if the line 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:
IllegalArgumentException - if any of the planes are 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:
IllegalArgumentException - if either input point 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:
IllegalArgumentException - if the line is null.

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.

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:
IllegalArgumentException - if the points array is null or any point within it is null.

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:
IllegalArgumentException - if either point is null.

toString

public final String toString()
Overrides:
toString in class Object

NASA World Wind