Package arc.math.geom

Class Ellipse

java.lang.Object
arc.math.geom.Ellipse
All Implemented Interfaces:
Shape2D

public class Ellipse extends Object implements Shape2D
A convenient 2D ellipse class, based on the circle class
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    float
     
    float
     
    float
     
    float
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Construct a new ellipse with all values set to zero
    Ellipse(float x, float y, float width, float height)
    Constructs a new ellipse
    Ellipse(Circle circle)
    Constructs a new Ellipse from the position and radius of a Circle (since circles are special cases of ellipses).
    Ellipse(Ellipse ellipse)
    Copy constructor
    Ellipse(Vec2 position, float width, float height)
    Costructs a new ellipse
    Ellipse(Vec2 position, Vec2 size)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    float
     
    float
    Approximates the circumference of this Ellipse.
    boolean
    contains(float x, float y)
    Checks whether or not this ellipse contains the given point.
    boolean
    contains(Vec2 point)
    Checks whether or not this ellipse contains the given point.
    boolean
     
    int
     
    void
    set(float x, float y, float width, float height)
    Sets a new position and size for this ellipse.
    void
    set(Circle circle)
     
    void
    set(Ellipse ellipse)
    Sets a new position and size for this ellipse based upon another ellipse.
    void
    set(Vec2 position, Vec2 size)
     
    setPosition(float x, float y)
    Sets the x and y-coordinates of ellipse center
    setPosition(Vec2 position)
    Sets the x and y-coordinates of ellipse center from a Vec2.
    setSize(float width, float height)
    Sets the width and height of this ellipse

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • x

      public float x
    • y

      public float y
    • width

      public float width
    • height

      public float height
  • Constructor Details

    • Ellipse

      public Ellipse()
      Construct a new ellipse with all values set to zero
    • Ellipse

      public Ellipse(Ellipse ellipse)
      Copy constructor
      Parameters:
      ellipse - Ellipse to construct a copy of.
    • Ellipse

      public Ellipse(float x, float y, float width, float height)
      Constructs a new ellipse
      Parameters:
      x - X coordinate
      y - Y coordinate
      width - the width of the ellipse
      height - the height of the ellipse
    • Ellipse

      public Ellipse(Vec2 position, float width, float height)
      Costructs a new ellipse
      Parameters:
      position - Position vector
      width - the width of the ellipse
      height - the height of the ellipse
    • Ellipse

      public Ellipse(Vec2 position, Vec2 size)
    • Ellipse

      public Ellipse(Circle circle)
      Constructs a new Ellipse from the position and radius of a Circle (since circles are special cases of ellipses).
      Parameters:
      circle - The circle to take the values of
  • Method Details

    • contains

      public boolean contains(float x, float y)
      Checks whether or not this ellipse contains the given point.
      Specified by:
      contains in interface Shape2D
      Parameters:
      x - X coordinate
      y - Y coordinate
      Returns:
      true if this ellipse contains the given point; false otherwise.
    • contains

      public boolean contains(Vec2 point)
      Checks whether or not this ellipse contains the given point.
      Specified by:
      contains in interface Shape2D
      Parameters:
      point - Position vector
      Returns:
      true if this ellipse contains the given point; false otherwise.
    • set

      public void set(float x, float y, float width, float height)
      Sets a new position and size for this ellipse.
      Parameters:
      x - X coordinate
      y - Y coordinate
      width - the width of the ellipse
      height - the height of the ellipse
    • set

      public void set(Ellipse ellipse)
      Sets a new position and size for this ellipse based upon another ellipse.
      Parameters:
      ellipse - The ellipse to copy the position and size of.
    • set

      public void set(Circle circle)
    • set

      public void set(Vec2 position, Vec2 size)
    • setPosition

      public Ellipse setPosition(Vec2 position)
      Sets the x and y-coordinates of ellipse center from a Vec2.
      Parameters:
      position - The position vector
      Returns:
      this ellipse for chaining
    • setPosition

      public Ellipse setPosition(float x, float y)
      Sets the x and y-coordinates of ellipse center
      Parameters:
      x - The x-coordinate
      y - The y-coordinate
      Returns:
      this ellipse for chaining
    • setSize

      public Ellipse setSize(float width, float height)
      Sets the width and height of this ellipse
      Parameters:
      width - The width
      height - The height
      Returns:
      this ellipse for chaining
    • area

      public float area()
      Returns:
      The area of this Ellipse as Mathf.PI * width * height
    • circumference

      public float circumference()
      Approximates the circumference of this Ellipse. Oddly enough, the circumference of an ellipse is actually difficult to compute exactly.
      Returns:
      The Ramanujan approximation to the circumference of an ellipse if one dimension is at least three times longer than the other, else the simpler approximation
    • equals

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

      public int hashCode()
      Overrides:
      hashCode in class Object