Package edu.cnu.mdi.geometry
Class Cylinder
java.lang.Object
edu.cnu.mdi.geometry.Cylinder
An infinite circular cylinder in three-dimensional Cartesian space.
The cylinder is defined by an infinite center line and a radius. Distances are measured relative to the cylinder surface: signed distances are negative inside the cylinder, zero on the surface, and positive outside the cylinder.
- Author:
- heddle
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanTests whether the cylinder center line lies on the z axis.doubledistance(double x, double y, double z) Computes the absolute shortest distance from coordinates to the cylinder surface.Gets the center line of the cylinder.doubleGets the radius of the cylinder.booleanisInside(double x, double y, double z) Tests whether coordinates are strictly inside the cylinder.booleanTests whether a point is strictly inside the cylinder.doublesignedDistance(double x, double y, double z) Computes the signed shortest distance from coordinates to the cylinder surface.doubleComputes the signed shortest distance from a point to the cylinder surface.
-
Constructor Details
-
Cylinder
Creates an infinite cylinder.- Parameters:
centerLine- the cylinder center lineradius- the cylinder radius; must be non-negative- Throws:
NullPointerException- ifcenterLineisnullIllegalArgumentException- ifradiusis negative or non-finite
-
Cylinder
public Cylinder(double[] p1, double[] p2, double radius) Creates an infinite cylinder from two points on its center line.- Parameters:
p1- one point on the center line as an xyz arrayp2- another point on the center line as an xyz arrayradius- the cylinder radius; must be non-negative- Throws:
NullPointerException- if either array isnullIndexOutOfBoundsException- if either array has fewer than three valuesIllegalArgumentException- ifradiusis negative or non-finite, or if the two center points do not define a stable line
-
-
Method Details
-
getCenterLine
Gets the center line of the cylinder.- Returns:
- a copy of the center line
-
getRadius
public double getRadius()Gets the radius of the cylinder.- Returns:
- the radius of the cylinder
-
signedDistance
Computes the signed shortest distance from a point to the cylinder surface.- Parameters:
p- the point- Returns:
- negative inside the cylinder, zero on the surface, and positive outside
- Throws:
NullPointerException- ifpisnull
-
signedDistance
public double signedDistance(double x, double y, double z) Computes the signed shortest distance from coordinates to the cylinder surface.- Parameters:
x- the x coordinatey- the y coordinatez- the z coordinate- Returns:
- negative inside the cylinder, zero on the surface, and positive outside
-
distance
public double distance(double x, double y, double z) Computes the absolute shortest distance from coordinates to the cylinder surface.- Parameters:
x- the x coordinatey- the y coordinatez- the z coordinate- Returns:
- the absolute distance to the cylinder surface
-
isInside
Tests whether a point is strictly inside the cylinder.- Parameters:
p- the point- Returns:
trueif the point is strictly inside the cylinder- Throws:
NullPointerException- ifpisnull
-
isInside
public boolean isInside(double x, double y, double z) Tests whether coordinates are strictly inside the cylinder.- Parameters:
x- the x coordinatey- the y coordinatez- the z coordinate- Returns:
trueif the point is strictly inside the cylinder
-
centeredOnZ
public boolean centeredOnZ()Tests whether the cylinder center line lies on the z axis.- Returns:
trueif both defining center-line points have x and y effectively zero
-