Class Cylinder

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

public class Cylinder extends Object
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
    Constructor
    Description
    Cylinder(double[] p1, double[] p2, double radius)
    Creates an infinite cylinder from two points on its center line.
    Cylinder(Line centerLine, double radius)
    Creates an infinite cylinder.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Tests whether the cylinder center line lies on the z axis.
    double
    distance(double x, double y, double z)
    Computes the absolute shortest distance from coordinates to the cylinder surface.
    Gets the center line of the cylinder.
    double
    Gets the radius of the cylinder.
    boolean
    isInside(double x, double y, double z)
    Tests whether coordinates are strictly inside the cylinder.
    boolean
    Tests whether a point is strictly inside the cylinder.
    double
    signedDistance(double x, double y, double z)
    Computes the signed shortest distance from coordinates to the cylinder surface.
    double
    Computes the signed shortest distance from a point to the cylinder surface.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Cylinder

      public Cylinder(Line centerLine, double radius)
      Creates an infinite cylinder.
      Parameters:
      centerLine - the cylinder center line
      radius - the cylinder radius; must be non-negative
      Throws:
      NullPointerException - if centerLine is null
      IllegalArgumentException - if radius is 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 array
      p2 - another point on the center line as an xyz array
      radius - the cylinder radius; must be non-negative
      Throws:
      NullPointerException - if either array is null
      IndexOutOfBoundsException - if either array has fewer than three values
      IllegalArgumentException - if radius is negative or non-finite, or if the two center points do not define a stable line
  • Method Details

    • getCenterLine

      public Line 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

      public double signedDistance(Point p)
      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 - if p is null
    • 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 coordinate
      y - the y coordinate
      z - 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 coordinate
      y - the y coordinate
      z - the z coordinate
      Returns:
      the absolute distance to the cylinder surface
    • isInside

      public boolean isInside(Point p)
      Tests whether a point is strictly inside the cylinder.
      Parameters:
      p - the point
      Returns:
      true if the point is strictly inside the cylinder
      Throws:
      NullPointerException - if p is null
    • isInside

      public boolean isInside(double x, double y, double z)
      Tests whether coordinates are strictly inside the cylinder.
      Parameters:
      x - the x coordinate
      y - the y coordinate
      z - the z coordinate
      Returns:
      true if the point is strictly inside the cylinder
    • centeredOnZ

      public boolean centeredOnZ()
      Tests whether the cylinder center line lies on the z axis.
      Returns:
      true if both defining center-line points have x and y effectively zero