Class BoundingBox

java.lang.Object
chemaxon.marvin.space.BoundingBox

@PublicAPI public class BoundingBox extends Object
Class for representing a bounding box of any component in the 3D space. Every GraphicComponent has a BoundingBox by default, but it has to be set. Edges of bounding boxes are always parallel to the coordinate axes.
For the sake of efficiency center and radius of the bounding box are not computed unless calling ready(), so that there is no unnecessary computation in case of setting many coordinates.

Example of typical usage:

 BoundingBox bb = new BoundingBox( 1, 2, 3, 4, 5, 6);
 
 BoundingBox bb = new BoundingBox();
 for(int i=0; i<atomCount; i++) {
      bb.setWithCondition(atomx, atomy, atomz);
 }
 bb.ready();
 
Since:
Marvin 4.0.2
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new instance of BoundingBox but does not set anything.
    BoundingBox(float minx, float miny, float minz, float maxx, float maxy, float maxz)
    Creates a bounding box with the given coordinates, computes the center and radius of the box.
  • Method Summary

    Modifier and Type
    Method
    Description
    float
    Returns the x coordinate of the center of the box.
    float
    Returns the y coordinate of the center of the box.
    float
    Returns the z coordinate of the center of the box.
    void
    Clears all previously set coordinate from the box.
    boolean
    contains(float x, float y, float z)
    Tells whether the given location is inside the box.
    void
    draw(com.jogamp.opengl.GL2 gl)
    Draws the box with the given GL2 in line mode.
    void
    extend(float v)
    Makes the bounding box being larger or smaller by the given value in each direction.
    float[]
    Returns the center of the box as a vector.
    double
    Returns the radius of the bounding sphere of the box, which is the distance between the lower-left-front corner and the center.
    float
    Returns the maximum x coordinate of the box.
    float
    Returns the maximum y coordinate of the box.
    float
    Returns the maximum z coordinate of the box.
    float
    Returns the minimum x coordinate of the box.
    float
    Returns the minimum y coordinate of the box.
    float
    Returns the minimum z coordinate of the box.
    float
    Returns the maximum x coordinate of the box.
    float
    Returns the maximum y coordinate of the box.
    float
    Returns the maximum z coordinate of the box.
    float
    Returns the minimum x coordinate of the box.
    float
    Returns the minimum y coordinate of the box.
    float
    Returns the minimum z coordinate of the box.
    void
    It has to be called after passing all coordinates to the box.
    void
    set(float minx, float miny, float minz, float maxx, float maxy, float maxz)
    Sets the minimum and maximum coordinates of the box.
    void
    setMax(float maxx, float maxy, float maxz)
    Sets the maximum coordinates of the box.
    void
    setMaxX(float v)
    Sets the maximum x coordinate of the box.
    void
    setMaxY(float v)
    Sets the maximum y coordinate of the box.
    void
    setMaxZ(float v)
    Sets the maximum z coordinate of the box.
    void
    setMin(float minx, float miny, float minz)
    Sets the minimum coordinates of the box.
    void
    setMinX(float v)
    Sets the minimum x coordinate of the box.
    void
    setMinY(float v)
    Sets the minimum y coordinate of the box.
    void
    setMinZ(float v)
    Sets the minimum z coordinate of the box.
    void
    setWithCondition(float x, float y, float z)
    This is the best way of passing coordinates to the box.
    void
    Extends the box with the given box, say gives the bounding box of the two boxes.
    Returns the minimum and maximum coordinates of the box.
    void
    translate(float[] v)
    A box can be translated in space.

    Methods inherited from class java.lang.Object

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

    • BoundingBox

      public BoundingBox()
      Creates a new instance of BoundingBox but does not set anything.
    • BoundingBox

      public BoundingBox(float minx, float miny, float minz, float maxx, float maxy, float maxz)
      Creates a bounding box with the given coordinates, computes the center and radius of the box.
  • Method Details

    • draw

      public void draw(com.jogamp.opengl.GL2 gl)
      Draws the box with the given GL2 in line mode.
      Parameters:
      gl - Interface to OpenGL
    • minx

      public float minx()
      Returns the minimum x coordinate of the box.
      Returns:
      minimum x coordinate
    • miny

      public float miny()
      Returns the minimum y coordinate of the box.
      Returns:
      minimum y coordinate
    • minz

      public float minz()
      Returns the minimum z coordinate of the box.
      Returns:
      minimum z coordinate
    • getMinX

      public float getMinX()
      Returns the minimum x coordinate of the box.
      Returns:
      minimum x coordinate
    • getMinY

      public float getMinY()
      Returns the minimum y coordinate of the box.
      Returns:
      minimum y coordinate
    • getMinZ

      public float getMinZ()
      Returns the minimum z coordinate of the box.
      Returns:
      minimum z coordinate
    • setMin

      public void setMin(float minx, float miny, float minz)
      Sets the minimum coordinates of the box.
      Parameters:
      minx - minimum x coordinate
      miny - minimum y coordinate
      minz - minimum z coordinate
    • setMinX

      public void setMinX(float v)
      Sets the minimum x coordinate of the box.
      Parameters:
      v - minimum x coordinate
    • setMinY

      public void setMinY(float v)
      Sets the minimum y coordinate of the box.
      Parameters:
      v - minimum y coordinate
    • setMinZ

      public void setMinZ(float v)
      Sets the minimum z coordinate of the box.
      Parameters:
      v - minimum z coordinate
    • maxx

      public float maxx()
      Returns the maximum x coordinate of the box.
      Returns:
      maximum x coordinate
    • maxy

      public float maxy()
      Returns the maximum y coordinate of the box.
      Returns:
      maximum y coordinate
    • maxz

      public float maxz()
      Returns the maximum z coordinate of the box.
      Returns:
      maximum z coordinate
    • getMaxX

      public float getMaxX()
      Returns the maximum x coordinate of the box.
      Returns:
      maximum x coordinate
    • getMaxY

      public float getMaxY()
      Returns the maximum y coordinate of the box.
      Returns:
      maximum y coordinate
    • getMaxZ

      public float getMaxZ()
      Returns the maximum z coordinate of the box.
      Returns:
      maximum z coordinate
    • setMax

      public void setMax(float maxx, float maxy, float maxz)
      Sets the maximum coordinates of the box.
      Parameters:
      maxx - maximum x coordinate
      maxy - maximum y coordinate
      maxz - maximum z coordinate
    • setMaxX

      public void setMaxX(float v)
      Sets the maximum x coordinate of the box.
      Parameters:
      v - maximum x coordinate
    • setMaxY

      public void setMaxY(float v)
      Sets the maximum y coordinate of the box.
      Parameters:
      v - maximum y coordinate
    • setMaxZ

      public void setMaxZ(float v)
      Sets the maximum z coordinate of the box.
      Parameters:
      v - maximum z coordinate
    • centerx

      public float centerx()
      Returns the x coordinate of the center of the box.
      Returns:
      x coordinate of the center
    • centery

      public float centery()
      Returns the y coordinate of the center of the box.
      Returns:
      y coordinate of the center
    • centerz

      public float centerz()
      Returns the z coordinate of the center of the box.
      Returns:
      z coordinate of the center
    • clear

      public void clear()
      Clears all previously set coordinate from the box.
    • ready

      public void ready()
      It has to be called after passing all coordinates to the box. It will compute the center and size of the box.
    • set

      public void set(float minx, float miny, float minz, float maxx, float maxy, float maxz)
      Sets the minimum and maximum coordinates of the box.
      Parameters:
      minx - minimum x coordinate
      miny - minimum y coordinate
      minz - minimum z coordinate
      maxx - maximum x coordinate
      maxy - maximum y coordinate
      maxz - maximum z coordinate
    • setWithCondition

      public void setWithCondition(float x, float y, float z)
      This is the best way of passing coordinates to the box. Condition means checking whether these are the first coordinates passed or not. If so, values are simply set as minimum and maximum, otherwise it checks if these are minimum or maximum values.
      Parameters:
      x - possible minimum and maximum x coordinate
      y - possible minimum and maximum y coordinate
      z - possible minimum and maximum z coordinate
    • setWithCondition

      public void setWithCondition(BoundingBox bb)
      Extends the box with the given box, say gives the bounding box of the two boxes.
      Parameters:
      bb - volume to add to the current volume defined by the boxes
    • extend

      public void extend(float v)
      Makes the bounding box being larger or smaller by the given value in each direction. Warning decreasing the size of the bounding box too much can cause error.
      Parameters:
      v - extension in Angstroms
    • getBoundingCenter

      public float[] getBoundingCenter()
      Returns the center of the box as a vector.
      Returns:
      center float coordinates of the box
    • getBoundingRadius

      public double getBoundingRadius()
      Returns the radius of the bounding sphere of the box, which is the distance between the lower-left-front corner and the center.
      Returns:
      half length the diagonal of the box
    • contains

      public boolean contains(float x, float y, float z)
      Tells whether the given location is inside the box.
    • translate

      public void translate(float[] v)
      A box can be translated in space. It is usually called by a LocationControl.
      Parameters:
      v - translation vector
    • toString

      public String toString()
      Returns the minimum and maximum coordinates of the box.
      Overrides:
      toString in class Object
      Returns:
      box as String