math.geom2d.conic
Class Ellipse2D

java.lang.Object
  extended by math.geom2d.conic.Ellipse2D
All Implemented Interfaces:
java.awt.Shape, Conic2D, Boundary2D, ContinuousBoundary2D, ContinuousCurve2D, ContinuousOrientedCurve2D, Curve2D, OrientedCurve2D, SmoothCurve2D, SmoothOrientedCurve2D, Shape2D
Direct Known Subclasses:
Circle2D

public class Ellipse2D
extends java.lang.Object
implements SmoothOrientedCurve2D, Conic2D, ContinuousBoundary2D, Boundary2D

An ellipse in the plane. It is defined by the center, the orientation angle, and the lengths of the two axis. No convention is taken about lengths of semiaxis : the second semi axis can be greater than the first one.


Field Summary
protected  boolean direct
          directed ellipse or not
protected  double r1
          length of semi axis
protected  double r2
          length of semi axis
protected  double theta
          orientation of first semi major axis
protected  double xc
          coordinate of center.
protected  double yc
           
 
Fields inherited from interface math.geom2d.conic.Conic2D
CIRCLE, ELLIPSE, HYPERBOLA, NOT_A_CONIC, PARABOLA, POINT, STRAIGHT_LINE, TWO_LINES
 
Fields inherited from interface math.geom2d.curve.ContinuousCurve2D
CLOSED_EDGE, LOOP, OPEN_EDGE
 
Fields inherited from interface math.geom2d.Shape2D
ACCURACY, defaultClipWindow, EMPTY_SET
 
Constructor Summary
Ellipse2D()
          Empty constructor, define ellipse centered at origin with both major and minor semi-axis with length equal to 1.
Ellipse2D(double xc, double yc, double l1, double l2)
          Define center by coordinate, plus major and minor semi axis
Ellipse2D(double xc, double yc, double l1, double l2, double theta)
          Define center by coordinate, major and minor semi axis lengths, and orientation angle.
Ellipse2D(double xc, double yc, double l1, double l2, double theta, boolean direct)
          Define center by coordinate, major and minor semi axis lengths, orientation angle, and boolean flag for directed ellipse.
Ellipse2D(java.awt.geom.Ellipse2D ellipse)
          construct an ellipse from the java.awt.geom class for ellipse.
Ellipse2D(Point2D center, double l1, double l2)
          Main constructor: define center by a point plus major and minor smei axis
Ellipse2D(Point2D center, double l1, double l2, double theta)
          Define center by point, major and minor semi axis lengths, and orientation angle.
 
Method Summary
 java.awt.geom.GeneralPath appendPath(java.awt.geom.GeneralPath path)
          Add the path of the ellipse to the given path.
 CurveSet2D<? extends SmoothOrientedCurve2D> clip(Box2D box)
          Clip the ellipse by a box.
 boolean contains(double x, double y)
          Return true if the point (x, y) lies on the ellipse, with precision given by Shape2D.ACCURACY.
 boolean contains(double x, double y, double w, double h)
          returns false, as an ellipse cannot contains a rectangle
 boolean contains(java.awt.geom.Point2D p)
          Return true if the point p lies on the ellipse, with precision given by Shape2D.ACCURACY.
 boolean contains(java.awt.geom.Rectangle2D rect)
          returns false, as an ellipse cannot contains a rectangle.
 boolean equals(java.lang.Object obj)
           
 double getAngle()
          return the angle of the ellipse first axis with the Ox axis.
 Polyline2D getAsPolyline(int n)
          return as a closed polyline with n line segments.
 java.util.Collection<ContinuousBoundary2D> getBoundaryCurves()
          Return the different continuous curves composing the boundary
 Box2D getBoundingBox()
          Return more precise bounds for the ellipse.
 java.awt.Rectangle getBounds()
          Return bounding box of the shape.
 java.awt.geom.Rectangle2D getBounds2D()
          Return more precise bounds for the shape.
 double[] getCartesianEquation()
          Return the coefficient of the cartesian representation of the conic.
 Point2D getCenter()
          return center of ellipse.
 int getConicType()
           
 java.util.Collection<ContinuousCurve2D> getContinuousCurves()
          Returns the collection of continuous curves which constitute this curve.
 double getCurvature(double t)
          returns the curvature of the ellipse.
 double getDistance(double x, double y)
          get the distance of the shape to the given point, specified by x and y, or the distance of point to the frontier of the shape in the case of a plain (i.e. fillable) shape.
 double getDistance(java.awt.geom.Point2D point)
          get the distance of the shape to the given point, or the distance of point to the frontier of the shape in the case of a plain shape.
 double getEccentricity()
          compute eccentricity of ellipse, depending on the lengths of the semi axis.
 Point2D getFirstPoint()
          Get the first point of the ellipse, which is the same as the last point.
 Point2D getFocus1()
          Return the first focus.
 Point2D getFocus2()
          Return the second focus.
protected  java.awt.geom.GeneralPath getGeneralPath()
           
 java.util.Collection<Point2D> getIntersections(StraightObject2D line)
          Compute intersections of the ellipse with a straight object (line, line segment, ray...).
 Point2D getLastPoint()
          Get the last point of the ellipse, which is the same as the first point.
 double getLength1()
          Returns the length of the first semi-axis of the ellipse.
 double getLength2()
          Returns the length of the second semi-axis of the ellipse.
 java.awt.geom.PathIterator getPathIterator(java.awt.geom.AffineTransform trans)
          Return pathiterator for this circle.
 java.awt.geom.PathIterator getPathIterator(java.awt.geom.AffineTransform trans, double flatness)
          Return pathiterator for this circle.
 Point2D getPoint(double t)
          get the position of the curve from internal parametric representation, depending on the parameter t.
 Point2D getPoint(double t, Point2D point)
          Same as getPoint(t), but gives the point as a parameter.
 double getPosition(Point2D point)
          Get position of the point on the curve.
 Point2D getProjectedPoint(java.awt.geom.Point2D point)
           
 Vector2D getProjectedVector(java.awt.geom.Point2D point, double eMax)
          Compute projection of a point onto an ellipse.
 Ellipse2D getReverseCurve()
          Returns the ellipse with same center and same radius, but with the other orientation.
 double getRho(double angle)
          Return the RHO parameter, in a polar representation of the ellipse, centered at the center of ellipse.
 double getSignedDistance(double x, double y)
          The same as getSignedDistance(Point2D), but by passing 2 double as arguments.
 double getSignedDistance(java.awt.geom.Point2D point)
          Get the signed distance of the curve to the given point : this distance is positive if the point lies outside the shape, and is negative if the point lies inside the shape.
 java.util.Collection<? extends SmoothCurve2D> getSmoothPieces()
          Returns a set of smooth curves, which contains only the ellipse.
 EllipseArc2D getSubCurve(double t0, double t1)
          return a new EllipseArc2D.
 double getT0()
          Returns the parameter of the first point of the ellipse, set to 0.
 double getT1()
          Returns the parameter of the last point of the ellipse, set to 2*PI.
 Vector2D getTangent(double t)
           
 Vector2D getVector1()
           
 Vector2D getVector2()
           
 double getWindingAngle(java.awt.geom.Point2D point)
          Return either 0, 2*PI or -2*PI, depending whether the point is located inside the interior of the ellipse or not.
 boolean intersects(double x, double y, double w, double h)
          Tests if the Ellipse intersects the interior of a specified rectangular area.
 boolean intersects(java.awt.geom.Rectangle2D r)
          Tests if the Ellipse intersects the interior of a specified rectangle2D.
 boolean isBounded()
          Always returns true, because an ellipse is bounded.
 boolean isCircle()
           
 boolean isClosed()
          return true, as an ellipse is always closed.
 boolean isDegenerated()
           
 boolean isDirect()
          return true if ellipse has a direct orientation.
 boolean isEllipse()
           
 boolean isHyperbola()
           
 boolean isInside(java.awt.geom.Point2D point)
          Test whether the point is inside the ellipse.
 boolean isParabola()
           
 boolean isPoint()
           
 boolean isStraightLine()
           
 boolean isTwoLines()
           
 double project(Point2D point)
          Returns the position of the closest orthogonal projection of the point on the curve, or of the closest singular point.
 void setCenter(double x, double y)
           
 void setCenter(Point2D center)
           
 void setEllipse(double xc, double yc, double r1, double r2, double theta)
           
 void setEllipse(double xc, double yc, double r1, double r2, double theta, boolean direct)
           
 void setEllipse(Point2D center, double r1, double r2, double theta)
           
 void setEllipse(Point2D center, double r1, double r2, double theta, boolean direct)
           
 java.lang.String toString()
           
 Ellipse2D transform(AffineTransform2D trans)
          Transforms this ellipse by an affine transform.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

xc

protected double xc
coordinate of center.


yc

protected double yc

r1

protected double r1
length of semi axis


r2

protected double r2
length of semi axis


theta

protected double theta
orientation of first semi major axis


direct

protected boolean direct
directed ellipse or not

Constructor Detail

Ellipse2D

public Ellipse2D()
Empty constructor, define ellipse centered at origin with both major and minor semi-axis with length equal to 1.


Ellipse2D

public Ellipse2D(Point2D center,
                 double l1,
                 double l2)
Main constructor: define center by a point plus major and minor smei axis


Ellipse2D

public Ellipse2D(double xc,
                 double yc,
                 double l1,
                 double l2)
Define center by coordinate, plus major and minor semi axis


Ellipse2D

public Ellipse2D(Point2D center,
                 double l1,
                 double l2,
                 double theta)
Define center by point, major and minor semi axis lengths, and orientation angle.


Ellipse2D

public Ellipse2D(double xc,
                 double yc,
                 double l1,
                 double l2,
                 double theta)
Define center by coordinate, major and minor semi axis lengths, and orientation angle.


Ellipse2D

public Ellipse2D(double xc,
                 double yc,
                 double l1,
                 double l2,
                 double theta,
                 boolean direct)
Define center by coordinate, major and minor semi axis lengths, orientation angle, and boolean flag for directed ellipse.


Ellipse2D

public Ellipse2D(java.awt.geom.Ellipse2D ellipse)
construct an ellipse from the java.awt.geom class for ellipse.

Method Detail

setEllipse

public void setEllipse(double xc,
                       double yc,
                       double r1,
                       double r2,
                       double theta)

setEllipse

public void setEllipse(double xc,
                       double yc,
                       double r1,
                       double r2,
                       double theta,
                       boolean direct)

setEllipse

public void setEllipse(Point2D center,
                       double r1,
                       double r2,
                       double theta)

setEllipse

public void setEllipse(Point2D center,
                       double r1,
                       double r2,
                       double theta,
                       boolean direct)

setCenter

public void setCenter(Point2D center)

setCenter

public void setCenter(double x,
                      double y)

getAsPolyline

public Polyline2D getAsPolyline(int n)
return as a closed polyline with n line segments.

Specified by:
getAsPolyline in interface ContinuousCurve2D
Parameters:
n - the number of line segments
Returns:
a closed polyline with n line segments.

getRho

public double getRho(double angle)
Return the RHO parameter, in a polar representation of the ellipse, centered at the center of ellipse.

Parameters:
angle - : angle from horizontal
Returns:
distance of ellipse from ellipse center in direction theta

getProjectedPoint

public Point2D getProjectedPoint(java.awt.geom.Point2D point)

getProjectedVector

public Vector2D getProjectedVector(java.awt.geom.Point2D point,
                                   double eMax)
Compute projection of a point onto an ellipse. Return the polar vector representing the translation from point point to its projection on the ellipse, with the direction parallel to the local normal to the ellipse. The parameter rho of the PolarVector2D is positive if point lies Refs :

http://www.spaceroots.org/documents/distance/distance-to-ellipse.pdf, http://www.spaceroots.org/downloads.html

Parameters:
point -
eMax -
Returns:
the projection vector

getConicType

public int getConicType()
Specified by:
getConicType in interface Conic2D

isEllipse

public boolean isEllipse()

isParabola

public boolean isParabola()

isHyperbola

public boolean isHyperbola()

isCircle

public boolean isCircle()

isStraightLine

public boolean isStraightLine()

isTwoLines

public boolean isTwoLines()

isPoint

public boolean isPoint()

isDegenerated

public boolean isDegenerated()

getCartesianEquation

public double[] getCartesianEquation()
Description copied from interface: Conic2D
Return the coefficient of the cartesian representation of the conic. Cartesian equation has the form :

a*x^2 + b*x*y + c*y^2 + d*x + e*y + f

The length of the array is then of size 6.

Specified by:
getCartesianEquation in interface Conic2D

getLength1

public double getLength1()
Returns the length of the first semi-axis of the ellipse.


getLength2

public double getLength2()
Returns the length of the second semi-axis of the ellipse.


getEccentricity

public double getEccentricity()
compute eccentricity of ellipse, depending on the lengths of the semi axis.

Specified by:
getEccentricity in interface Conic2D

getCenter

public Point2D getCenter()
return center of ellipse.


getFocus1

public Point2D getFocus1()
Return the first focus. It ius defined as the first focus on the Major axis, in the direction given by angle theta.


getFocus2

public Point2D getFocus2()
Return the second focus. It is defined as the second focus on the Major axis, in the direction given by angle theta.


getVector1

public Vector2D getVector1()

getVector2

public Vector2D getVector2()

getAngle

public double getAngle()
return the angle of the ellipse first axis with the Ox axis.


isDirect

public boolean isDirect()
return true if ellipse has a direct orientation.


getTangent

public Vector2D getTangent(double t)
Specified by:
getTangent in interface SmoothCurve2D

getCurvature

public double getCurvature(double t)
returns the curvature of the ellipse.

Specified by:
getCurvature in interface SmoothCurve2D

getBoundaryCurves

public java.util.Collection<ContinuousBoundary2D> getBoundaryCurves()
Description copied from interface: Boundary2D
Return the different continuous curves composing the boundary

Specified by:
getBoundaryCurves in interface Boundary2D

getSmoothPieces

public java.util.Collection<? extends SmoothCurve2D> getSmoothPieces()
Returns a set of smooth curves, which contains only the ellipse.

Specified by:
getSmoothPieces in interface ContinuousCurve2D

isClosed

public boolean isClosed()
return true, as an ellipse is always closed.

Specified by:
isClosed in interface ContinuousCurve2D

getWindingAngle

public double getWindingAngle(java.awt.geom.Point2D point)
Return either 0, 2*PI or -2*PI, depending whether the point is located inside the interior of the ellipse or not.

Specified by:
getWindingAngle in interface OrientedCurve2D
Parameters:
point - a point of the plane
Returns:
a signed angle

isInside

public boolean isInside(java.awt.geom.Point2D point)
Test whether the point is inside the ellipse. The test is performed by rotating the ellipse and the point to align with axis, rescaling in each direction, then computing distance to origin.

Specified by:
isInside in interface OrientedCurve2D
Parameters:
point - a point in the plane
Returns:
true if the point is on the left side of the curve.

getSignedDistance

public double getSignedDistance(java.awt.geom.Point2D point)
Description copied from interface: OrientedCurve2D
Get the signed distance of the curve to the given point : this distance is positive if the point lies outside the shape, and is negative if the point lies inside the shape. In this case, absolute value of distance is equals to the distance to the border of the shape.

Specified by:
getSignedDistance in interface OrientedCurve2D
Parameters:
point - a point of the plane
Returns:
the signed distance to the curve

getSignedDistance

public double getSignedDistance(double x,
                                double y)
Description copied from interface: OrientedCurve2D
The same as getSignedDistance(Point2D), but by passing 2 double as arguments.

Specified by:
getSignedDistance in interface OrientedCurve2D
Parameters:
x - x-coord of a point
y - y-coord of a point
Returns:
the signed distance of the point (x,y) to the curve

getT0

public double getT0()
Returns the parameter of the first point of the ellipse, set to 0.

Specified by:
getT0 in interface Curve2D

getT1

public double getT1()
Returns the parameter of the last point of the ellipse, set to 2*PI.

Specified by:
getT1 in interface Curve2D

getPoint

public Point2D getPoint(double t)
get the position of the curve from internal parametric representation, depending on the parameter t. This parameter is between the two limits 0 and 2*Math.PI.

Specified by:
getPoint in interface Curve2D

getPoint

public Point2D getPoint(double t,
                        Point2D point)
Description copied from interface: Curve2D
Same as getPoint(t), but gives the point as a parameter. This avoids repetitive memory allocations.

Specified by:
getPoint in interface Curve2D

getFirstPoint

public Point2D getFirstPoint()
Get the first point of the ellipse, which is the same as the last point.

Specified by:
getFirstPoint in interface Curve2D
Returns:
the first point of the curve

getLastPoint

public Point2D getLastPoint()
Get the last point of the ellipse, which is the same as the first point.

Specified by:
getLastPoint in interface Curve2D
Returns:
the last point of the curve.

getPosition

public double getPosition(Point2D point)
Description copied from interface: Curve2D
Get position of the point on the curve. If the point does not belong to the curve, return Double.NaN.

Specified by:
getPosition in interface Curve2D
Parameters:
point - a point belonging to the curve
Returns:
the position of the point on the curve

project

public double project(Point2D point)
Description copied from interface: Curve2D
Returns the position of the closest orthogonal projection of the point on the curve, or of the closest singular point. This function should always returns a valid value.

Specified by:
project in interface Curve2D
Parameters:
point - a point to project
Returns:
the position of the closest orthogonal projection

getReverseCurve

public Ellipse2D getReverseCurve()
Returns the ellipse with same center and same radius, but with the other orientation.

Specified by:
getReverseCurve in interface Conic2D
Specified by:
getReverseCurve in interface Boundary2D
Specified by:
getReverseCurve in interface ContinuousBoundary2D
Specified by:
getReverseCurve in interface ContinuousCurve2D
Specified by:
getReverseCurve in interface ContinuousOrientedCurve2D
Specified by:
getReverseCurve in interface Curve2D
Specified by:
getReverseCurve in interface OrientedCurve2D
Specified by:
getReverseCurve in interface SmoothCurve2D
Specified by:
getReverseCurve in interface SmoothOrientedCurve2D

getContinuousCurves

public java.util.Collection<ContinuousCurve2D> getContinuousCurves()
Description copied from interface: Curve2D
Returns the collection of continuous curves which constitute this curve.

Specified by:
getContinuousCurves in interface Curve2D
Returns:
a collection of continuous curves.

getSubCurve

public EllipseArc2D getSubCurve(double t0,
                                double t1)
return a new EllipseArc2D.

Specified by:
getSubCurve in interface ContinuousCurve2D
Specified by:
getSubCurve in interface ContinuousOrientedCurve2D
Specified by:
getSubCurve in interface Curve2D
Specified by:
getSubCurve in interface SmoothCurve2D
Specified by:
getSubCurve in interface SmoothOrientedCurve2D
Parameters:
t0 - position of the start of the sub-curve
t1 - position of the end of the sub-curve
Returns:
the portion of original curve comprised between t0 and t1.

isBounded

public boolean isBounded()
Always returns true, because an ellipse is bounded.

Specified by:
isBounded in interface Shape2D

getDistance

public double getDistance(java.awt.geom.Point2D point)
Description copied from interface: Shape2D
get the distance of the shape to the given point, or the distance of point to the frontier of the shape in the case of a plain shape.

Specified by:
getDistance in interface Shape2D

getDistance

public double getDistance(double x,
                          double y)
Description copied from interface: Shape2D
get the distance of the shape to the given point, specified by x and y, or the distance of point to the frontier of the shape in the case of a plain (i.e. fillable) shape.

Specified by:
getDistance in interface Shape2D

clip

public CurveSet2D<? extends SmoothOrientedCurve2D> clip(Box2D box)
Clip the ellipse by a box. The result is an instance of CurveSet2D, which contains only instances of Ellipse2D or EllipseArc2D. If the ellipse is not clipped, the result is an instance of CurveSet2D which contains 0 curves.

Specified by:
clip in interface Conic2D
Specified by:
clip in interface ContinuousCurve2D
Specified by:
clip in interface ContinuousOrientedCurve2D
Specified by:
clip in interface Curve2D
Specified by:
clip in interface OrientedCurve2D
Specified by:
clip in interface SmoothCurve2D
Specified by:
clip in interface SmoothOrientedCurve2D
Specified by:
clip in interface Shape2D
Parameters:
box - the clipping box
Returns:
the clipped shape

getBoundingBox

public Box2D getBoundingBox()
Return more precise bounds for the ellipse. Return an instance of Box2D.

Specified by:
getBoundingBox in interface Shape2D
Returns:
the bounding box of the shape.

getIntersections

public java.util.Collection<Point2D> getIntersections(StraightObject2D line)
Compute intersections of the ellipse with a straight object (line, line segment, ray...).

Principle of the algorithm is to transform line and ellipse such that ellipse becomes a circle, then using the intersections computation from circle.

Specified by:
getIntersections in interface Curve2D

transform

public Ellipse2D transform(AffineTransform2D trans)
Transforms this ellipse by an affine transform. If the transformed shape is a circle (ellipse with equal axis lengths), returns an instance of Circle2D.

Specified by:
transform in interface Conic2D
Specified by:
transform in interface Boundary2D
Specified by:
transform in interface ContinuousBoundary2D
Specified by:
transform in interface ContinuousCurve2D
Specified by:
transform in interface ContinuousOrientedCurve2D
Specified by:
transform in interface Curve2D
Specified by:
transform in interface OrientedCurve2D
Specified by:
transform in interface SmoothCurve2D
Specified by:
transform in interface SmoothOrientedCurve2D
Specified by:
transform in interface Shape2D
Parameters:
trans - an affine transform
Returns:
the transformed shape

contains

public boolean contains(java.awt.geom.Point2D p)
Return true if the point p lies on the ellipse, with precision given by Shape2D.ACCURACY.

Specified by:
contains in interface java.awt.Shape

contains

public boolean contains(double x,
                        double y)
Return true if the point (x, y) lies on the ellipse, with precision given by Shape2D.ACCURACY.

Specified by:
contains in interface java.awt.Shape

contains

public boolean contains(double x,
                        double y,
                        double w,
                        double h)
returns false, as an ellipse cannot contains a rectangle

Specified by:
contains in interface java.awt.Shape

contains

public boolean contains(java.awt.geom.Rectangle2D rect)
returns false, as an ellipse cannot contains a rectangle.

Specified by:
contains in interface java.awt.Shape

getBounds

public java.awt.Rectangle getBounds()
Return bounding box of the shape.

Specified by:
getBounds in interface java.awt.Shape

getBounds2D

public java.awt.geom.Rectangle2D getBounds2D()
Return more precise bounds for the shape.

Specified by:
getBounds2D in interface java.awt.Shape

intersects

public boolean intersects(double x,
                          double y,
                          double w,
                          double h)
Tests if the Ellipse intersects the interior of a specified rectangular area.

Specified by:
intersects in interface java.awt.Shape

intersects

public boolean intersects(java.awt.geom.Rectangle2D r)
Tests if the Ellipse intersects the interior of a specified rectangle2D.

Specified by:
intersects in interface java.awt.Shape

appendPath

public java.awt.geom.GeneralPath appendPath(java.awt.geom.GeneralPath path)
Add the path of the ellipse to the given path.

Specified by:
appendPath in interface ContinuousCurve2D
Parameters:
path - the path to be completed
Returns:
the completed path

getGeneralPath

protected java.awt.geom.GeneralPath getGeneralPath()

getPathIterator

public java.awt.geom.PathIterator getPathIterator(java.awt.geom.AffineTransform trans)
Return pathiterator for this circle.

Specified by:
getPathIterator in interface java.awt.Shape

getPathIterator

public java.awt.geom.PathIterator getPathIterator(java.awt.geom.AffineTransform trans,
                                                  double flatness)
Return pathiterator for this circle.

Specified by:
getPathIterator in interface java.awt.Shape

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object