Class Cylinder

  • All Implemented Interfaces:
    Extent, Renderable

    public class Cylinder
    extends java.lang.Object
    implements Extent, Renderable
    Represents a geometric cylinder, most often used as a bounding volume. Cylinders are immutable.
    • Field Detail

      • bottomCenter

        protected final Vec4 bottomCenter
      • topCenter

        protected final Vec4 topCenter
      • axisUnitDirection

        protected final Vec4 axisUnitDirection
      • cylinderRadius

        protected final double cylinderRadius
      • cylinderHeight

        protected final double cylinderHeight
    • Constructor Detail

      • Cylinder

        public Cylinder​(Vec4 bottomCenter,
                        Vec4 topCenter,
                        double cylinderRadius)
        Create a Cylinder from two points and a radius.
        Parameters:
        bottomCenter - the center point of of the cylinder's base.
        topCenter - the center point of the cylinders top.
        cylinderRadius - the cylinder's radius.
        Throws:
        java.lang.IllegalArgumentException - if the radius is zero or the top or bottom point is null or they are coincident.
      • Cylinder

        public Cylinder​(Vec4 bottomCenter,
                        Vec4 topCenter,
                        double cylinderRadius,
                        Vec4 unitDirection)
        Create a Cylinder from two points, a radius and an axis direction. Provided for use when unit axis is know and computation of it can be avoided.
        Parameters:
        bottomCenter - the center point of of the cylinder's base.
        topCenter - the center point of the cylinders top.
        cylinderRadius - the cylinder's radius.
        unitDirection - the unit-length axis of the cylinder.
        Throws:
        java.lang.IllegalArgumentException - if the radius is zero or the top or bottom point is null or they are coincident.
    • Method Detail

      • getAxisUnitDirection

        public Vec4 getAxisUnitDirection()
        Returns the unit-length axis of this cylinder.
        Returns:
        the unit-length axis of this cylinder.
      • getBottomCenter

        public Vec4 getBottomCenter()
        Returns the this cylinder's bottom-center point.
        Returns:
        this cylinder's bottom-center point.
      • getTopCenter

        public Vec4 getTopCenter()
        Returns the this cylinder's top-center point.
        Returns:
        this cylinder's top-center point.
      • getCylinderRadius

        public double getCylinderRadius()
        Returns this cylinder's radius.
        Returns:
        this cylinder's radius.
      • getCylinderHeight

        public double getCylinderHeight()
        Returns this cylinder's height.
        Returns:
        this cylinder's height.
      • getCenter

        public Vec4 getCenter()
        Return this cylinder's center point.
        Specified by:
        getCenter in interface Extent
        Returns:
        this cylinder's center point.
      • getDiameter

        public double getDiameter()
        Returns the extent's diameter. The computation of the diameter depends on the implementing class. See the documentation for the individual classes to determine how they compute a diameter.
        Specified by:
        getDiameter in interface Extent
        Returns:
        the extent's diameter.
      • getRadius

        public double getRadius()
        Returns the extent's radius. The computation of the radius depends on the implementing class. See the documentation for the individual classes to determine how they compute a radius.
        Specified by:
        getRadius in interface Extent
        Returns:
        the extent's radius.
      • getVolume

        public double getVolume()
        Return this cylinder's volume.
        Returns:
        this cylinder's volume.
      • intersect

        public Intersection[] intersect​(Line line)
        Computes the intersections of this extent with line. The returned array may be either null or of zero length if no intersections are discovered. It does not contain null elements. Tangential intersections are marked as such. line is considered to have infinite length in both directions.
        Specified by:
        intersect in interface Extent
        Parameters:
        line - the Line with which to intersect this Extent.
        Returns:
        an array of intersections representing all the points where line enters or leave this Extent.
      • intersects

        public boolean intersects​(Line line)
        Determines whether or not line intersects this Extent. This method may be faster than checking the size of the array returned by intersect(Line). Implementing methods must ensure that this method returns true if and only if intersect(Line) returns a non-null array containing at least one element.
        Specified by:
        intersects in interface Extent
        Parameters:
        line - the Line with which to test for intersection.
        Returns:
        true if an intersection is found, false otherwise.
      • intcyl

        protected boolean intcyl​(Vec4 raybase,
                                 Vec4 raycos,
                                 Vec4 base,
                                 Vec4 axis,
                                 double radius,
                                 double[] tVals)
      • clipcyl

        protected boolean clipcyl​(Vec4 raybase,
                                  Vec4 raycos,
                                  Vec4 bot,
                                  Vec4 top,
                                  Vec4 axis,
                                  double[] tVals)
      • intersects

        protected double intersects​(Plane plane,
                                    double effectiveRadius)
      • intersectsAt

        protected double intersectsAt​(Plane plane,
                                      double effectiveRadius,
                                      Vec4[] endpoints)
      • getEffectiveRadius

        public double getEffectiveRadius​(Plane plane)
        Computes the effective radius of the extent relative to a specified plane.
        Specified by:
        getEffectiveRadius in interface Extent
        Parameters:
        plane - the plane.
        Returns:
        the effective radius, or 0 if the plane is null.
      • intersects

        public boolean intersects​(Plane plane)
        Calculate whether or not this Extent is intersected by plane.
        Specified by:
        intersects in interface Extent
        Parameters:
        plane - the Plane with which to test for intersection.
        Returns:
        true if plane is found to intersect this Extent.
      • intersects

        public boolean intersects​(Frustum frustum)
        Determines whether or not this Extent intersects frustum. Returns true if any part of these two objects intersect, including the case where either object wholly contains the other, false otherwise.
        Specified by:
        intersects in interface Extent
        Parameters:
        frustum - the Frustum with which to test for intersection.
        Returns:
        true if there is an intersection, false otherwise.
      • getProjectedArea

        public double getProjectedArea​(View view)
        Computes the area in square pixels of this Extent after it is projected into the specified view's viewport. The returned value is the screen area that this Extent covers in the infinite plane defined by the view's viewport. This area is not limited to the size of the view's viewport, and portions of this Extent are not clipped by the view's frustum.

        This returns Double.POSITIVE_INFINITY if the view's eye point is inside this Extent, or if any portion of this Extent is behind the eye point. In either case, this Extent has no finite projection on the view.

        Specified by:
        getProjectedArea in interface Extent
        Parameters:
        view - the View for which to compute a projected screen area.
        Returns:
        the projected screen area of this Extent in square pixels, or Double.POSITIVE_INFINITY if the view's eye point is inside this Extent or part of this Extent is behind the view's eye point.
      • computeVerticalBoundingCylinder

        public static Cylinder computeVerticalBoundingCylinder​(Globe globe,
                                                               double verticalExaggeration,
                                                               Sector sector)
        Returns a cylinder that minimally surrounds the specified minimum and maximum elevations in the sector at a specified vertical exaggeration, and is oriented such that the cylinder axis is perpendicular to the globe's surface.
        Parameters:
        globe - The globe associated with the sector.
        verticalExaggeration - the vertical exaggeration to apply to the minimum and maximum elevations when computing the cylinder.
        sector - the sector to return the bounding cylinder for.
        Returns:
        The minimal bounding cylinder in Cartesian coordinates.
        Throws:
        java.lang.IllegalArgumentException - if sector is null
        See Also:
        computeBoundingCylinder(Iterable)
      • computeVerticalBoundingCylinder

        public static Cylinder computeVerticalBoundingCylinder​(Globe globe,
                                                               double verticalExaggeration,
                                                               Sector sector,
                                                               double minElevation,
                                                               double maxElevation)
        Returns a cylinder that minimally surrounds the specified minimum and maximum elevations in the sector at a specified vertical exaggeration, and is oriented such that the cylinder axis is perpendicular to the globe's surface.
        Parameters:
        globe - The globe associated with the sector.
        verticalExaggeration - the vertical exaggeration to apply to the minimum and maximum elevations when computing the cylinder.
        sector - the sector to return the bounding cylinder for.
        minElevation - the minimum elevation of the bounding cylinder.
        maxElevation - the maximum elevation of the bounding cylinder.
        Returns:
        The minimal bounding cylinder in Cartesian coordinates.
        Throws:
        java.lang.IllegalArgumentException - if sector is null
        See Also:
        computeBoundingCylinder(Iterable)
      • computeVerticalBoundsFromSectorLatitudeRange

        protected static Cylinder computeVerticalBoundsFromSectorLatitudeRange​(Globe globe,
                                                                               Sector sector,
                                                                               double minHeight,
                                                                               double maxHeight)
        Compute the Cylinder that surrounds the equator, and has height defined by the sector's minumum and maximum latitudes (including maxHeight).
        Parameters:
        globe - The globe associated with the sector.
        sector - the sector to return the bounding cylinder for.
        minHeight - the minimum height to include in the bounding cylinder.
        maxHeight - the maximum height to include in the bounding cylinder.
        Returns:
        the minimal bounding cylinder in Cartesianl coordinates.
        Throws:
        java.lang.IllegalArgumentException - if sector is null
      • computeVerticalBoundsFromSectorQuadrilateral

        protected static Cylinder computeVerticalBoundsFromSectorQuadrilateral​(Globe globe,
                                                                               Sector sector,
                                                                               double minHeight,
                                                                               double maxHeight)
        Returns a cylinder that minimally surrounds the specified height range in the sector.
        Parameters:
        globe - The globe associated with the sector.
        sector - the sector to return the bounding cylinder for.
        minHeight - the minimum height to include in the bounding cylinder.
        maxHeight - the maximum height to include in the bounding cylinder.
        Returns:
        The minimal bounding cylinder in Cartesian coordinates.
        Throws:
        java.lang.IllegalArgumentException - if sector is null
      • computeVerticalBoundsFromSectorVertices

        protected static Cylinder computeVerticalBoundsFromSectorVertices​(Globe globe,
                                                                          Sector sector,
                                                                          double minHeight,
                                                                          double maxHeight)
        Returns a cylinder that surrounds the specified height range in the zero-area sector. The returned cylinder won't be as tight a fit as computeBoundsFromSectorQuadrilateral.
        Parameters:
        globe - The globe associated with the sector.
        sector - the sector to return the bounding cylinder for.
        minHeight - the minimum height to include in the bounding cylinder.
        maxHeight - the maximum height to include in the bounding cylinder.
        Returns:
        The minimal bounding cylinder in Cartesian coordinates.
        Throws:
        java.lang.IllegalArgumentException - if sector is null
      • render

        public void render​(DrawContext dc)
        Display the cylinder.
        Specified by:
        render in interface Renderable
        Parameters:
        dc - the current draw context.
        Throws:
        java.lang.IllegalArgumentException - if the draw context is null.
        See Also:
        DrawContext
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object