org.gicentre.utils.geom
Class Ellipse

java.lang.Object
  extended by org.gicentre.utils.geom.Ellipse

public class Ellipse
extends java.lang.Object

Class for representing an ellipse. Unlike Processing's own ellipse command this can represent ellipses with axes aligned at any angle. See also www.spaceroots.org/documents/ellipse for some of the mathematical derivations used in this class.

Version:
3.3, 6th April 2013.
Author:
Jo Wood, giCentre, City University London.

Constructor Summary
Ellipse(double cx, double cy, double eWidth, double eHeight)
          Creates and ellipse with axes aligned to coordinate axes.
Ellipse(double cx, double cy, double eWidth, double eHeight, double theta)
          Creates and ellipse major axis orientated at the given angle.
 
Method Summary
static double clockwiseAngleBetween(double startAngle, double endAngle)
          Calculates the clockwise angle between the given first and second angles.
 processing.core.PVector[] getBezier(double startAngle, double endAngle)
          Provides the cubic Bezier anchor (p) and control points (q) that approximate the elliptical arc between the two given angles.
 processing.core.PVector[] getBezierVertices(double startAngle, double endAngle)
          Provides a collection of Bezier anchor (p) and control (q) points representing the elliptical arc between the given angles.
 processing.core.PVector getCentre()
          Reports the centre position of the ellipse.
 processing.core.PVector getFocus1()
          Reports the first focus of the ellipse.
 processing.core.PVector getFocus2()
          Reports the second focus of the ellipse.
 double getMajor()
          Reports the semi-major axis of the ellipse (its longest radius from the centre to circumference).
 double getMinor()
          Reports the semi-minor axis of the ellipse (its shortest radius from the centre to circumference).
 processing.core.PVector getPosition(double lamda)
          Reports the elliptical position for any given angle lambda.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Ellipse

public Ellipse(double cx,
               double cy,
               double eWidth,
               double eHeight)
Creates and ellipse with axes aligned to coordinate axes.

Parameters:
cx - x-coordinate of the centre of the ellipse.
cy - y-coordinate of the centre of the ellipse.
eWidth - Width of the ellipse.
eHeight - Height of the ellipse.

Ellipse

public Ellipse(double cx,
               double cy,
               double eWidth,
               double eHeight,
               double theta)
Creates and ellipse major axis orientated at the given angle.

Parameters:
cx - x-coordinate of the centre of the ellipse.
cy - y-coordinate of the centre of the ellipse.
eWidth - Width of the ellipse.
eHeight - Height of the ellipse.
theta - Orientation of the major axis (in radians).
Method Detail

getPosition

public processing.core.PVector getPosition(double lamda)
Reports the elliptical position for any given angle lambda.

Parameters:
lamda - Angle in radians from which elliptical position is to be calculated.
Returns:
Position on circumference of ellipse corresponding to the given angle.

getBezier

public processing.core.PVector[] getBezier(double startAngle,
                                           double endAngle)
Provides the cubic Bezier anchor (p) and control points (q) that approximate the elliptical arc between the two given angles. Note that accuracy will depend on the eccentricity of the ellipse and the curvature of the given angular segment. Where more accurate representations, especially for larger angular segments, consider using getBezierVertices() instead.

Parameters:
startAngle - First angle in arc (radians).
endAngle - Second angle in arc (radians).
Returns:
Array containing vertex points and control points in the order [p1,q1,q2,p2] which matches the order required by Processing's own bezier() method.

getBezierVertices

public processing.core.PVector[] getBezierVertices(double startAngle,
                                                   double endAngle)
Provides a collection of Bezier anchor (p) and control (q) points representing the elliptical arc between the given angles. Unlike getBezier(), this method can be used to define any arc length from 0 to 2PI radians and should be visibly accurate.

Parameters:
startAngle - First angle in arc (radians).
endAngle - Second angle in arc (radians).
Returns:
Array containing vertex points and control points in the order [p1,q1,q2,p2,q3,q4,p3...etc.] which matches the order required when calling Processing's own bezierVertex() methods from between beginShape() and endShape(). Note that when doing this, the first anchor point (p1) should be fixed with a call to vertex().

clockwiseAngleBetween

public static double clockwiseAngleBetween(double startAngle,
                                           double endAngle)
Calculates the clockwise angle between the given first and second angles.

Parameters:
startAngle - First angle in arc (radians).
endAngle - Second angle in arc (radians).
Returns:
Clockwise angle between the given angles (can be more than 2PI radians).

getCentre

public processing.core.PVector getCentre()
Reports the centre position of the ellipse.

Returns:
Centre position of the ellipse.

getMajor

public double getMajor()
Reports the semi-major axis of the ellipse (its longest radius from the centre to circumference).

Returns:
semi-major axis.

getMinor

public double getMinor()
Reports the semi-minor axis of the ellipse (its shortest radius from the centre to circumference).

Returns:
semi-minor axis.

getFocus1

public processing.core.PVector getFocus1()
Reports the first focus of the ellipse.

Returns:
First focus of the ellipse.

getFocus2

public processing.core.PVector getFocus2()
Reports the second focus of the ellipse.

Returns:
Second focus of the ellipse.


giCentre Utilities V.3.3, API documentation generated 6th April, 2013