Package gov.nasa.worldwind.geom
Class Plane
- java.lang.Object
-
- gov.nasa.worldwind.geom.Plane
-
public class Plane extends java.lang.Object
Represents a plane in Cartesian coordinates. The plane's X, Y and Z components indicate the plane's normal vector. The distance component indicates the plane's distance from the origin relative to its unit normal.
-
-
Constructor Summary
Constructors Constructor Description Plane()
Constructs a plane in the X-Y plane with its unit normal pointing along the Z axis.Plane(double x, double y, double z, double distance)
Constructs a plane with specified normal vector components and distance from the origin.Plane(Plane plane)
Constructs a plane with the normal vector and distance from a specified plane.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Vec3[]
clip(Vec3 pointA, Vec3 pointB)
Clips a line segment to this plane, returning an two-point array indicating the clipped segment.double
distanceToPoint(Vec3 point)
Computes the distance between this plane and a point.double
dot(Vec3 vector)
Computes the dot product of this plane's components with a specified vector.boolean
equals(java.lang.Object o)
int
hashCode()
boolean
intersectsSegment(Vec3 endPoint1, Vec3 endPoint2)
Determines whether a specified line segment intersects this plane.int
onSameSide(Vec3 pointA, Vec3 pointB)
Determines whether two points are on the same side of this plane.Plane
set(double x, double y, double z, double distance)
Sets this plane's specified normal vector and distance to specified values.Plane
set(Plane plane)
Sets this plane's normal vector and distance to that of a specified plane.java.lang.String
toString()
Plane
transformByMatrix(Matrix4 matrix)
Transforms this plane by a specified matrix.
-
-
-
Constructor Detail
-
Plane
public Plane()
Constructs a plane in the X-Y plane with its unit normal pointing along the Z axis.
-
Plane
public Plane(double x, double y, double z, double distance)
Constructs a plane with specified normal vector components and distance from the origin. This constructor normalizes the components, ensuring that the plane has a unit normal vector.- Parameters:
x
- the X component of the plane's normal vectory
- the Y component of the plane's normal vectorz
- the Z component of the plane's normal vectordistance
- the plane's distance from the origin
-
Plane
public Plane(Plane plane)
Constructs a plane with the normal vector and distance from a specified plane.- Parameters:
plane
- the plane specifying the normal vector and distance- Throws:
java.lang.IllegalArgumentException
- If the plane is null
-
-
Method Detail
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
@NonNull public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
distanceToPoint
public double distanceToPoint(Vec3 point)
Computes the distance between this plane and a point.- Parameters:
point
- the point whose distance to compute- Returns:
- the computed distance
- Throws:
java.lang.IllegalArgumentException
- If the vector is null
-
set
public Plane set(double x, double y, double z, double distance)
Sets this plane's specified normal vector and distance to specified values. This normalizes the components, ensuring that the plane has a unit normal vector.- Parameters:
x
- the X component of the plane's normal vectory
- the Y component of the plane's normal vectorz
- the Z component of the plane's normal vectordistance
- the plane's distance from the origin- Returns:
- this plane with its normal vector and distance set to specified values
-
set
public Plane set(Plane plane)
Sets this plane's normal vector and distance to that of a specified plane.- Parameters:
plane
- the plane specifying the normal vector and distance- Returns:
- this plane with its normal vector and distance set to those of the specified plane
- Throws:
java.lang.IllegalArgumentException
- If the plane is null
-
transformByMatrix
public Plane transformByMatrix(Matrix4 matrix)
Transforms this plane by a specified matrix.- Parameters:
matrix
- the matrix to apply to this plane- Returns:
- this plane transformed by the specified matrix
- Throws:
java.lang.IllegalArgumentException
- If the matrix is null
-
dot
public double dot(Vec3 vector)
Computes the dot product of this plane's components with a specified vector. Since the plane was defined with a unit normal vector, this function returns the distance of the vector from the plane.- Parameters:
vector
- the vector to dot with this plane's components- Returns:
- the computed dot product
- Throws:
java.lang.IllegalArgumentException
- If the vector is null
-
intersectsSegment
public boolean intersectsSegment(Vec3 endPoint1, Vec3 endPoint2)
Determines whether a specified line segment intersects this plane.- Parameters:
endPoint1
- the line segment's first end pointendPoint2
- the line segment's second end point- Returns:
- true if the line segment intersects this plane, otherwise false
-
onSameSide
public int onSameSide(Vec3 pointA, Vec3 pointB)
Determines whether two points are on the same side of this plane.- Parameters:
pointA
- the first pointpointB
- the second point- Returns:
- -1 if both points are on the negative side of this plane, +1 if both points are on the positive side of this plane, 0 if the points are on opposite sides of this plane
- Throws:
java.lang.IllegalArgumentException
- If either point is null
-
clip
public Vec3[] clip(Vec3 pointA, Vec3 pointB)
Clips a line segment to this plane, returning an two-point array indicating the clipped segment. 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.- Parameters:
pointA
- the first line segment endpointpointB
- the second line segment endpoint- Returns:
- an array of two points both on the positive side of the plane, or null if the segment does not intersect this plane
- Throws:
java.lang.IllegalArgumentException
- If either point is null
-
-