Package toxi.geom

Class Ellipse

All Implemented Interfaces:
Comparable<ReadonlyVec2D>, ReadonlyVec2D, Shape2D
Direct Known Subclasses:
Circle

public class Ellipse extends Vec2D implements Shape2D
This class defines a 2D ellipse and provides several utility methods for it.
  • Field Details

    • DEFAULT_RES

      public static int DEFAULT_RES
  • Constructor Details

    • Ellipse

      public Ellipse()
    • Ellipse

      public Ellipse(float rx, float ry)
    • Ellipse

      public Ellipse(float x, float y, float r)
    • Ellipse

      public Ellipse(float x, float y, float rx, float ry)
    • Ellipse

      public Ellipse(ReadonlyVec2D v, float r)
    • Ellipse

      public Ellipse(ReadonlyVec2D v, ReadonlyVec2D r)
  • Method Details

    • containsPoint

      public boolean containsPoint(ReadonlyVec2D p)
      Description copied from interface: Shape2D
      Checks if the point is within the given shape.
      Specified by:
      containsPoint in interface Shape2D
      Returns:
      true, if inside
    • getArea

      public float getArea()
      Computes the area covered by the ellipse.
      Specified by:
      getArea in interface Shape2D
      Returns:
      area
    • getBoundingCircle

      public Circle getBoundingCircle()
      Description copied from interface: Shape2D
      Computes the bounding circle of the shape.
      Specified by:
      getBoundingCircle in interface Shape2D
      Returns:
      circle
    • getBounds

      public Rect getBounds()
      Returns the ellipse's bounding rect.
      Specified by:
      getBounds in interface Shape2D
      Returns:
      bounding rect
      See Also:
    • getCircumference

      public float getCircumference()
      Computes the approximate circumference of the ellipse, using this equation: 2 * PI * sqrt(1/2 * (rx*rx+ry*ry)). The precise value is an infinite series elliptical integral, but the approximation comes sufficiently close. See Wikipedia for more details: http://en.wikipedia.org/wiki/Ellipse
      Specified by:
      getCircumference in interface Shape2D
      Returns:
      circumference
    • getEdges

      public List<Line2D> getEdges()
      Description copied from interface: Shape2D
      Returns a list of the shape's perimeter edges.
      Specified by:
      getEdges in interface Shape2D
      Returns:
      list of Line2D elements
    • getFoci

      public Vec2D[] getFoci()
      Returns:
      the focus
    • getRadii

      public Vec2D getRadii()
      Returns:
      the 2 radii of the ellipse as a Vec2D
    • getRandomPoint

      public Vec2D getRandomPoint()
      Creates a random point within the ellipse using a BiasedFloatRange to create a more uniform distribution.
      Specified by:
      getRandomPoint in interface Shape2D
      Returns:
      Vec2D
    • setRadii

      public Ellipse setRadii(float rx, float ry)
      Sets the radii of the ellipse to the new values.
      Parameters:
      rx -
      ry -
      Returns:
      itself
    • setRadii

      public Ellipse setRadii(ReadonlyVec3D r)
      Sets the radii of the ellipse to the values given by the vector.
      Parameters:
      r -
      Returns:
      itself
    • toPolygon2D

      public Polygon2D toPolygon2D()
      Description copied from interface: Shape2D
      Converts the shape into a Polygon2D instance (possibly via a default resolution, e.g. for circles/ellipses)
      Specified by:
      toPolygon2D in interface Shape2D
      Returns:
      shape as polygon
    • toPolygon2D

      public Polygon2D toPolygon2D(int res)
      Creates a Polygon2D instance of the ellipse sampling it at the given resolution.
      Parameters:
      res - number of steps
      Returns:
      ellipse as polygon