Class AxisAlignedBoundingBox

java.lang.Object
imagingbook.common.geometry.hulls.AxisAlignedBoundingBox
All Implemented Interfaces:
ShapeProducer

public class AxisAlignedBoundingBox extends Object implements ShapeProducer

Represents a major axis-aligned bounding box of a 2D point set. At least one point is required to set up a bounding box. If the direction vector is undefined (e.g., in the case of a single input point), the unit vector in x-direction is assumed. See Sec. 8.6.4 (Alg. 8.6) of [1] for details.

[1] W. Burger, M.J. Burge, Digital Image Processing – An Algorithmic Introduction, 3rd ed, Springer (2022).

Version:
2022/11/01
  • Field Details

  • Constructor Details

  • Method Details

    • getOrientationVector

      public double[] getOrientationVector()
      Returns the orientation vector of this bounding box (pointing in the direction of its major axis).
      Returns:
      the orientation vector of this bounding box
    • getBoundingLines

      Returns an array of four AlgebraicLine instances which coincide with the outline of the bounding box. The lines can be used to determine if a given point is inside the box or not (see contains(Pnt2d, double)).
      Returns:
      an array of bounding lines
    • getVertices

      public Pnt2d[] getVertices()
      Returns an array holding the 4 corner points of the bounding box.
      Returns:
      as described above
    • getShape

      public Path2D getShape(double scale)
      Description copied from interface: ShapeProducer
      Returns a scaled Shape for this object (default scale is 1). Must be defined by implementing classes. The interpretation of the scale factor is left to the implementing class. For example, for Pnt2d it specifies the size of the marker (see Pnt2d.getShape(double).
      Specified by:
      getShape in interface ShapeProducer
      Parameters:
      scale - the scale of the shape
      Returns:
      a Shape instance
    • getShapes

      public Shape[] getShapes(double scale)
      Description copied from interface: ShapeProducer
      Returns a fixed sequence of Shape items for drawing this object, which must contain at least one item. This is to produce graphic representations that are too complex for a single Shape item. The returned shapes may also be displayed with different strokes or colors.

      By default, this method returns a single item which is the primary shape (obtained by ShapeProducer.getShape(double)). Implementing classes should override this method if more than one shape must be returned For example, a GeometricEllipse returns three shape items: (a) the ellipse curve, (b) the center mark, (c) the major axes (see GeometricEllipse.getShapes(double)).

      Specified by:
      getShapes in interface ShapeProducer
      Parameters:
      scale - a scale factor (may be used or ignored)
      Returns:
      sequence of Shape items
    • contains

      public boolean contains(Pnt2d p)
      Checks if this bounding box contains the specified point using the default tolerance. This method is used instead of Path2D.contains(double, double) to avoid false results due to roundoff errors.
      Parameters:
      p - some 2D point
      Returns:
      true if the point is inside the bounding box
    • contains

      public boolean contains(Pnt2d p, double tolerance)
      Checks if this bounding box contains the specified point using the specified tolerance. This method is used instead of Path2D.contains(double, double) to avoid false results due to roundoff errors.
      Parameters:
      p - some 2D point
      tolerance - positive quantity for being outside
      Returns:
      true if the point is inside the bounding box
    • toString

      public String toString()
      Overrides:
      toString in class Object