Class Rectangle3D

java.lang.Object
org.bzdev.geom.Rectangle3D
All Implemented Interfaces:
Cloneable, Shape3D
Direct Known Subclasses:
Rectangle3D.Double, Rectangle3D.Float

public abstract class Rectangle3D extends Object implements Shape3D, Cloneable
Class representing a rectangular cuboid aligned with respect to the X, Y, and Z axes. The API is modeled after the API for Rectangle2D in order to reduce the learning curve.

A point is considered to lie inside the rectangular cuboid, and thus to be contained by it, if all of the following are true:

  • the point is completely inside the cuboid.
  • the point lies on the boundary and the space adjacent to
  • the point is on the boundary of the cuboid and there exists a point with a larger X value that is inside the cuboid
  • the point is on the boundary of the cuboid and there exists a point with a larger Y value that is inside the cuboid
  • the point is on the boundary of the cuboid and there exists a point with a larger Z value that is inside the cuboid
This convention is meant to mimic the convention used by the Shape interface and specifically the class Rectangle2D.

Note: this documentation was in part based nearly literally on the documentation for the class Rectangle2D.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    Subclass of Rectangle3D that stores its values as double-precision numbers.
    static class 
    Subclass of Rectangle3D that stores its values as single-precision numbers.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final Object
    Psuedo tag.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(double newx, double newy, double newz)
    Adds a point, specified by its coordinates, to this Rectangle3D.
    void
    Adds a point to this Rectangle3D.
    void
    Adds a Rectangle3D object to this Rectangle3D.
     
    boolean
    contains(double x, double y, double z)
    Tests if the specified coordinates are inside this Rectangle3D.
    boolean
    contains(double x, double y, double z, double w, double h, double d)
    Tests if all the points inside the specified rectangular cuboid, specified by coordinates and dimensions, are inside this cuboid.
    boolean
    Test if a point is contained by this rectangular cuboid.
    boolean
    Tests if all the points inside the specified rectangular cuboid are inside this cuboid.
    Returns a new Rectangle3D object representing the intersection of this Rectangle3D with the specified Rectangle3D.
    Returns a new Rectangle3D object representing the union of this Rectangle3D with the specified Rectangle3D.
    boolean
     
    Get the boundary for this Shape3D.
    Get a bounding rectangular cuboid for a 3D shape.
    double
    Get the X coordinate for the center of this rectangular cuboid.
    double
    Get the Y coordinate for the center of this rectangular cuboid.
    double
    Get the Z coordinate for the center of this rectangular cuboid.
    getComponent(int i)
    Get a component of this shape.
    abstract double
    Get the depth of this rectangular cuboid.
    abstract double
    Get the height of this rectangular cuboid.
    double
    /** Get the maximum X coordinate for this rectangular cuboid
    double
    Get the maximum Y coordinate for this rectangular cuboid
    double
    Get the maximum Z coordinate for this rectangular cuboid
    abstract double
    Get the minimum X coordinate for this rectangular cuboid
    abstract double
    Get the minimum Y coordinate for this rectangular cuboid
    abstract double
    Get the minimum Z coordinate for this rectangular cuboid
    Get a surface iterator for this object.
    getSurfaceIterator(Transform3D tform, int level)
    Get a surface iterator for this Shape3D, subdividing the surface.
    abstract double
    Get the width of this rectangular cuboid.
    int
     
    static void
    Intersects two source Rectangle3D objects and puts the result into the specified destination Rectangle3D object.
    boolean
    intersects(double x, double y, double z, double w, double h, double d)
    Determine if this rectangular cuboid intersects a rectangular cuboid that is specified by its corner and the length of its edges.
    boolean
    Determine if this rectangular cuboid intersects another rectangular cuboid.
    boolean
    Determine if this Shape3D is a closed two-dimensional manifold.
    boolean
    Tests if a Rectangle3D object is empty.
    boolean
    Determine if a surface is oriented.
    int
    Get the number of components for this shape.
    void
    Set a rectangle's color.
    abstract void
    setRect(double x, double y, double z, double w, double h, double d)
    Set the configuration of this object given explicit coordinates and dimensions
    void
    Set the configuration of this object to that of a specified Rectangle3D.
    void
    setRectFromCenter(double centerX, double centerY, double centerZ, double cornerX, double cornerY, double cornerZ)
    Set the configuration of this object based on the coordinates of the center of this cuboid and the coordinates of a corner.
    void
    Set the configuration of this object based on points at the center of this cuboid and a corner of this cuboid.
    void
    setRectFromDiagonal(double x1, double y1, double z1, double x2, double y2, double z2)
    Set the configuration of this object based on the coordinates of vertices that lie along a diagonal.
    void
    Set the configuration of this object based on vertices that lie along a diagonal.
    static void
    Sets a destination Rectangle3D to the union of two source Rectangle3D objects.

    Methods inherited from class java.lang.Object

    finalize, getClass, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.bzdev.geom.Shape3D

    getBoundary
  • Field Details

    • STACKTRACE

      public static final Object STACKTRACE
      Psuedo tag. Using this object as a tag will cause the tag to be a stack trace.
  • Constructor Details

    • Rectangle3D

      public Rectangle3D()
  • Method Details

    • isOriented

      public boolean isOriented()
      Description copied from interface: Shape3D
      Determine if a surface is oriented.
      Specified by:
      isOriented in interface Shape3D
      Returns:
      true if the surface has an orientation; false if it does not
    • getBoundary

      public Path3D getBoundary()
      Description copied from interface: Shape3D
      Get the boundary for this Shape3D. For a closed surface, the boundary will be an empty path.

      Typically, a boundary will consist of a series of distinct closed subpaths. Subpaths are separated by segments whose type is {link PathIterator3D#SEG_MOVETO}. For a closed manifold, the boundary will be an empty path.

      Specified by:
      getBoundary in interface Shape3D
      Returns:
      the boundary of this surface; null if a boundary cannot be computed
      See Also:
    • isClosedManifold

      public boolean isClosedManifold()
      Description copied from interface: Shape3D
      Determine if this Shape3D is a closed two-dimensional manifold.
      Specified by:
      isClosedManifold in interface Shape3D
      Returns:
      true if the surface is a closed two-dimensional manifold; false otherwise
    • numberOfComponents

      public int numberOfComponents()
      Description copied from interface: Shape3D
      Get the number of components for this shape. Components are connected shapes - surfaces for which every point can connect to any other point.
      Specified by:
      numberOfComponents in interface Shape3D
      Returns:
      the number of components for this shape
    • getComponent

      public Shape3D getComponent(int i) throws IllegalArgumentException
      Description copied from interface: Shape3D
      Get a component of this shape. Components are connected shapes - surfaces for which every point can connect to any other point. The components are referenced by an index, specified as an integer in the range [0,n), where n is the number of manifold components. If n is zero, no index is valid.
      Specified by:
      getComponent in interface Shape3D
      Parameters:
      i - the component's index
      Returns:
      a model containing the specified component
      Throws:
      IllegalArgumentException - the argument is out of range
      See Also:
    • setColor

      public void setColor(Color c)
      Set a rectangle's color.
      Parameters:
      c - the color for this rectangle; null if none is specified
    • add

      public void add(double newx, double newy, double newz)
      Adds a point, specified by its coordinates, to this Rectangle3D. The resulting Rectangle3D is the smallest Rectangle3D that contains both the original Rectangle3D and the specified point (newx, newy, newz) specified by the arguments.

      After adding a point, a call to contains with the added point as an argument does not necessarily return true. The contains method does not return true for points on the right or bottom edges of a rectangle. Therefore, if the added point falls on the left or bottom edge of the enlarged rectangle, contains returns false for that point.

      Parameters:
      newx - the X coordinate of the new point
      newy - the Y coordinate of the new point
      newz - the Z coordinate of the new point
    • add

      public void add(Point3D p)
      Adds a point to this Rectangle3D. The resulting Rectangle3D is the smallest Rectangle3D that contains both the original Rectangle3D and the specified point (newx, newy, newz) specified by the arguments.

      After adding a point, a call to contains with the added point as an argument does not necessarily return true. The contains method does not return true for points on the right or bottom edges of a rectangle. Therefore, if the added point falls on the left or bottom edge of the enlarged rectangle, contains returns false for that point.

      Parameters:
      p - the new point
    • add

      public void add(Rectangle3D r)
      Adds a Rectangle3D object to this Rectangle3D. The resulting Rectangle3D is the union of the two Rectangle2D objects.
      Parameters:
      r - the rectangle to add
    • createIntersection

      public Rectangle3D createIntersection(Rectangle3D r)
      Returns a new Rectangle3D object representing the intersection of this Rectangle3D with the specified Rectangle3D.
      Parameters:
      r - the Rectangle2D to be intersected with this Rectangle3D
      Returns:
      the largest Rectangle3D contained in both the specified Rectangle3D and in this Rectangle3D.
    • createUnion

      public Rectangle3D createUnion(Rectangle3D r)
      Returns a new Rectangle3D object representing the union of this Rectangle3D with the specified Rectangle3D.
      Parameters:
      r - the Rectangle3D to be intersected with this Rectangle3D
      Returns:
      the smallest Rectangle3D containing both the specified Rectangle3D and this Rectangle2D
    • contains

      public boolean contains(double x, double y, double z)
      Tests if the specified coordinates are inside this Rectangle3D. A point is contained by this rectangle if it is inside it.
      Parameters:
      x - the X coordinate
      y - the Y coordinate
      z - the Z coordinate
      Returns:
      true if the point denoted by the specified coordinates are inside this cuboid; false otherwise
    • contains

      public boolean contains(double x, double y, double z, double w, double h, double d)
      Tests if all the points inside the specified rectangular cuboid, specified by coordinates and dimensions, are inside this cuboid. A point is contained by this rectangle if it is inside it.
      Parameters:
      x - the X coordinate of the specified cuboid's minimum X value
      y - the Y coordinate of the specified cuboid's minimum Y value
      z - the Z coordinate of the specified cuboid's minimum Z value
      w - the width of the specified cuboid (its length in the X direction)
      h - the height of the specified cuboid (its length in the Y direction)
      d - the depth of the specified cuboid (its length in the Z direction)
      Returns:
      true if the specified rectangular cuboid are inside this cuboid; false otherwise
    • contains

      public boolean contains(Point3D p)
      Test if a point is contained by this rectangular cuboid. A point is contained by this rectangle if it is inside it.
      Parameters:
      p - a point
      Returns:
      true if the specified point is within this cuboid; false otherwise
    • contains

      public boolean contains(Rectangle3D r)
      Tests if all the points inside the specified rectangular cuboid are inside this cuboid. A point is contained by this rectangle if it is inside it.
      Parameters:
      r - the specified rectangular cuboid
      Returns:
      true if the points inside r are within this cuboid; false otherwise
    • getHeight

      public abstract double getHeight()
      Get the height of this rectangular cuboid. The height is defined as the length in the Y direction.
      Returns:
      the height
    • getWidth

      public abstract double getWidth()
      Get the width of this rectangular cuboid. The width is defined as the length in the X direction.
      Returns:
      the width
    • getDepth

      public abstract double getDepth()
      Get the depth of this rectangular cuboid. The depth is defined as the length in the Z direction.
      Returns:
      the depth
    • getMinX

      public abstract double getMinX()
      Get the minimum X coordinate for this rectangular cuboid
      Returns:
      the minimum X coordinate
    • getMinY

      public abstract double getMinY()
      Get the minimum Y coordinate for this rectangular cuboid
      Returns:
      the minimum Y coordinate
    • getMinZ

      public abstract double getMinZ()
      Get the minimum Z coordinate for this rectangular cuboid
      Returns:
      the minimum Z coordinate
    • getMaxX

      public double getMaxX()
      /** Get the maximum X coordinate for this rectangular cuboid
      Returns:
      the maximum X coordinate
    • getMaxY

      public double getMaxY()
      Get the maximum Y coordinate for this rectangular cuboid
      Returns:
      the maximum Y coordinate
    • getMaxZ

      public double getMaxZ()
      Get the maximum Z coordinate for this rectangular cuboid
      Returns:
      the maximum Z coordinate
    • getCenterX

      public double getCenterX()
      Get the X coordinate for the center of this rectangular cuboid.
      Returns:
      the X coordinate for the center of this rectangular cuboid
    • getCenterY

      public double getCenterY()
      Get the Y coordinate for the center of this rectangular cuboid.
      Returns:
      the Y coordinate for the center of this rectangular cuboid
    • getCenterZ

      public double getCenterZ()
      Get the Z coordinate for the center of this rectangular cuboid.
      Returns:
      the Z coordinate for the center of this rectangular cuboid
    • intersects

      public boolean intersects(Rectangle3D r)
      Determine if this rectangular cuboid intersects another rectangular cuboid.
      Parameters:
      r - the other rectangular cuboid
      Returns:
      true if this cuboid and the other cuboid intersect; false otherwise
    • intersects

      public boolean intersects(double x, double y, double z, double w, double h, double d)
      Determine if this rectangular cuboid intersects a rectangular cuboid that is specified by its corner and the length of its edges.
      Parameters:
      x - the X coordinate of the specified cuboid's minimum X value
      y - the Y coordinate of the specified cuboid's minimum Y value
      z - the Z coordinate of the specified cuboid's minimum Z value
      w - the width of the specified cuboid (its length in the X direction)
      h - the height of the specified cuboid (its length in the Y direction)
      d - the depth of the specified cuboid (its length in the Z direction)
      Returns:
      true if this cuboid and the specified cuboid intersect; false otherwise
    • intersect

      public static void intersect(Rectangle3D src1, Rectangle3D src2, Rectangle3D dest)
      Intersects two source Rectangle3D objects and puts the result into the specified destination Rectangle3D object. The destination object can be one of the source objects, if desired, in which case a source object will be overridden.
      Parameters:
      src1 - the first source Rectangle3D object
      src2 - the second source Rectangle3D object
      dest - the destination Rectangle3D object
    • isEmpty

      public boolean isEmpty()
      Tests if a Rectangle3D object is empty. A Rectangle3D is empty if its width, height, and depth are all zero.
      Returns:
      true if this object is empty; false otherwise
    • clone

      public Object clone()
      Overrides:
      clone in class Object
    • getBounds

      public Rectangle3D getBounds()
      Description copied from interface: Shape3D
      Get a bounding rectangular cuboid for a 3D shape. The edges will be aligned with the X, Y and Z axes. The cuboid created may not be the smallest one possible (for example, shapes defined by Bézier surfaces may just use the control points to determine the cuboid as the convex hull for the control points includes all of the surface for parameters in the normal range [0,1]).
      Specified by:
      getBounds in interface Shape3D
      Returns:
      a bounding rectangular cuboid for this Shape3D; null if the shape does not contain any points
    • getSurfaceIterator

      public SurfaceIterator getSurfaceIterator(Transform3D tform)
      Get a surface iterator for this object.

      The transform should either be an affine transform or well-approximated by an affine transform over the surface of this rectangle.

      Specified by:
      getSurfaceIterator in interface Shape3D
      Parameters:
      tform - a transform to apply to the cuboid; null if the identity transform will be used
      Returns:
      a surface iterator
    • getSurfaceIterator

      public SurfaceIterator getSurfaceIterator(Transform3D tform, int level)
      Description copied from interface: Shape3D
      Get a surface iterator for this Shape3D, subdividing the surface. The surface iterator will represent the shape as a sequence of Bézier patches and Bézier triangles, with the order of the sequence arbitrary.

      Unless the transform is an affine transform, the transformation is not exact. In this case, the patches and triangles that constitute the surface after each is subdivided should be small enough that the transform can be approximated by an affine transform over the region containing the control points.

      Specified by:
      getSurfaceIterator in interface Shape3D
      Parameters:
      tform - a transform to apply to each control point; null for the identity transform
      level - the number of levels of partitioning (each additional level splits the previous level into quarters)
      Returns:
      a surface iterator
    • setRect

      public abstract void setRect(double x, double y, double z, double w, double h, double d)
      Set the configuration of this object given explicit coordinates and dimensions
      Parameters:
      x - the X coordinate of the vertex whose coordinates have a minimal value.
      y - the Y coordinate of the vertex whose coordinates have a minimal value.
      z - the Z coordinate of the vertex whose coordinates have a minimal value.
      w - the width of the object (the length in the X direction)
      h - the height of the object (the length in the Y direction)
      d - the depth of the object (the length in the Z direction)
    • setRect

      public void setRect(Rectangle3D r)
      Set the configuration of this object to that of a specified Rectangle3D.
      Parameters:
      r - the object that will be copied.
    • setRectFromDiagonal

      public void setRectFromDiagonal(double x1, double y1, double z1, double x2, double y2, double z2)
      Set the configuration of this object based on the coordinates of vertices that lie along a diagonal.
      Parameters:
      x1 - the X coordinate of the first vertex
      y1 - the Y coordinate of the first vertex
      z1 - the Z coordinate of the first vertex
      x2 - the X coordinate of the second vertex
      y2 - the Y coordinate of the second vertex
      z2 - the Z coordinate of the second vertex
    • setRectFromDiagonal

      public void setRectFromDiagonal(Point3D p1, Point3D p2)
      Set the configuration of this object based on vertices that lie along a diagonal.
      Parameters:
      p1 - a point at the location of the first vertex
      p2 - a point at the location of the second vertex
    • setRectFromCenter

      public void setRectFromCenter(double centerX, double centerY, double centerZ, double cornerX, double cornerY, double cornerZ)
      Set the configuration of this object based on the coordinates of the center of this cuboid and the coordinates of a corner.
      Parameters:
      centerX - the X coordinate of the center of the desired cuboid
      centerY - the Y coordinate of the center of the desired cuboid
      centerZ - the Y coordinate of the center of the desired cuboid
      cornerX - the X coordinate of a corner of the desired cuboid
      cornerY - the Y coordinate of a corner of the desired cuboid
      cornerZ - the Y coordinate of a corner of the desired cuboid
    • setRectFromCenter

      public void setRectFromCenter(Point3D center, Point3D corner)
      Set the configuration of this object based on points at the center of this cuboid and a corner of this cuboid.
      Parameters:
      center - a point positioned at the center of the desired cuboid
      corner - a point positioned at a corner of the desired cuboid
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • union

      public static void union(Rectangle3D src1, Rectangle3D src2, Rectangle3D dest)
      Sets a destination Rectangle3D to the union of two source Rectangle3D objects. The destination object can be one of the source objects, if desired, in which case a source object will be overridden.
      Parameters:
      src1 - the first source Rectangle3D object
      src2 - the second source Rectangle3D object
      dest - the destination Rectangle3D object