math.geom2d.conic
Class Ellipse2D
- java.lang.Object
-
- math.geom2d.curve.AbstractContinuousCurve2D
-
- math.geom2d.curve.AbstractSmoothCurve2D
-
- math.geom2d.conic.Ellipse2D
-
- All Implemented Interfaces:
- java.lang.Cloneable, Conic2D, EllipseShape2D, ContinuousCurve2D, Curve2D, SmoothCurve2D, Boundary2D, ContinuousOrientedCurve2D, Contour2D, OrientedCurve2D, SmoothContour2D, SmoothOrientedCurve2D, GeometricObject2D, Shape2D
public class Ellipse2D extends AbstractSmoothCurve2D implements EllipseShape2D, java.lang.Cloneable
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.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface math.geom2d.conic.Conic2D
Conic2D.Type
-
-
Constructor Summary
Constructors Constructor and Description 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 axisEllipse2D(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 semi axisEllipse2D(Point2D center, double l1, double l2, double theta)Define center by point, major and minor semi axis lengths, and orientation angle.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method and Description booleanalmostEquals(GeometricObject2D obj, double eps)Checks if the two objects are similar up to a given threshold value.doubleangle()Returns the angle of the ellipse first axis with the Ox axis.java.awt.geom.GeneralPathappendPath(java.awt.geom.GeneralPath path)Add the path of the ellipse to the given path.LinearRing2DasPolyline(int n)Converts this continuous curve to an instance of LinearCurve2D with the given number of edges.Box2DboundingBox()Return more precise bounds for the ellipse.Point2Dcenter()Returns center of the ellipse.CurveSet2D<? extends SmoothOrientedCurve2D>clip(Box2D box)Clip the ellipse by a box.Ellipse2Dclone()Deprecated.use copy constructor instead (0.11.2)double[]conicCoefficients()Returns the conic coefficients of the ellipse.Conic2D.TypeconicType()booleancontains(double x, double y)Returns true if the point (x, y) lies on the ellipse, with precision given by Shape2D.ACCURACY.booleancontains(Point2D p)Returns true if the point p lies on the ellipse, with precision given by Shape2D.ACCURACY.java.util.Collection<? extends Ellipse2D>continuousCurves()Returns the collection of continuous curves which constitute this curve.static Ellipse2Dcreate(java.awt.geom.Ellipse2D ellipse)Deprecated.since 0.11.1static Ellipse2Dcreate(Point2D center, double l1, double l2)Deprecated.since 0.11.1static Ellipse2Dcreate(Point2D center, double l1, double l2, double theta)Deprecated.since 0.11.1static Ellipse2Dcreate(Point2D center, double l1, double l2, double theta, boolean direct)Define center by point, major and minor semi axis lengths, orientation angle, and boolean flag for direct ellipse.static Ellipse2Dcreate(Point2D focus1, Point2D focus2, double chord)Create a new Ellipse by specifying the two focii, and the length of the chord.doublecurvature(double t)Returns the curvature of the ellipse.doubledistance(double x, double y)Returns 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.doubledistance(Point2D point)Computes distance using a polyline approximation.Domain2Ddomain()Returns the domain delimited by this boundary.voiddraw(java.awt.Graphics2D g2)Draws the curve on the given Graphics2D object.doubleeccentricity()Computes eccentricity of ellipse, depending on the lengths of the semi-axes.booleanequals(java.lang.Object obj)voidfill(java.awt.Graphics2D g2)Fills the interior of the boundary, using the Graphics current Paint.Point2DfirstPoint()Returns the first point of the ellipse, which is the same as the last point.Point2Dfocus1()Return the first focus.Point2Dfocus2()Returns the second focus.java.awt.geom.GeneralPathgetGeneralPath()doublegetRho(double angle)Return the RHO parameter, in a polar representation of the ellipse, centered at the center of ellipse.doublegetT0()Deprecated.replaced by t0() (since 0.11.1).doublegetT1()Deprecated.replaced by t1() (since 0.11.1).static Ellipse2DinertiaEllipse(java.util.Collection<Point2D> points)java.util.Collection<Point2D>intersections(LinearShape2D line)Compute intersections of the ellipse with a straight object (line, line segment, ray...).booleanisBounded()Always returns true.booleanisCircle()Returns true if this ellipse is similar to a circle, i.e.booleanisClosed()Returns true, as an ellipse is always closed.booleanisDirect()Returns true if ellipse has a direct orientation.booleanisEmpty()Always returns false.booleanisInside(Point2D point)Test whether the point is inside the ellipse.Point2DlastPoint()Returns the last point of the ellipse, which is the same as the first point.Ellipse2Dparallel(double d)Return the parallel ellipse located at a distance d from this ellipse.Point2Dpoint(double t)get the position of the curve from internal parametric representation, depending on the parameter t.doubleposition(Point2D point)Computes the position of the point on the curve.doubleproject(Point2D point)Computes the approximate projection position of the point on the ellipse.Point2DprojectedPoint(Point2D point)Vector2DprojectedVector(Point2D point, double eMax)Compute projection of a point onto an ellipse.static Ellipse2DreduceCentered(double[] coefs)Creates a new Ellipse by reducing the conic coefficients, assuming conic type is ellipse, and ellipse is centered.Ellipse2Dreverse()Returns the ellipse with same center and same radius, but with the other orientation.doublesemiMajorAxisLength()Returns the length of the major semi-axis of the ellipse.doublesemiMinorAxisLength()Returns the length of the minor semi-axis of the ellipse.doublesignedDistance(double x, double y)The same as distanceSigned(Point2D), but by passing 2 double as arguments.doublesignedDistance(Point2D point)Returns an approximation of the signed distance to the ellipse.EllipseArc2DsubCurve(double t0, double t1)return a new EllipseArc2D.doublet0()Returns the parameter of the first point of the ellipse, set to 0.doublet1()Returns the parameter of the last point of the ellipse, set to 2*PI.Vector2Dtangent(double t)Returns the tangent of the curve at the given position.java.lang.StringtoString()Ellipse2Dtransform(AffineTransform2D trans)Transforms this ellipse by an affine transform.static Ellipse2DtransformCentered(Ellipse2D ellipse, AffineTransform2D trans)Transform an ellipse, by supposing both the ellipse is centered and the transform has no translation part.Vector2Dvector1()Returns the first direction vector of the ellipse, in the direction of the major axis.Vector2Dvector2()Returns the second direction vector of the ellipse, in the direction of the minor axis.doublewindingAngle(Point2D point)Return either 0, 2*PI or -2*PI, depending whether the point is located inside the interior of the ellipse or not.-
Methods inherited from class math.geom2d.curve.AbstractSmoothCurve2D
isSingular, leftTangent, normal, rightTangent, singularPoints, smoothPieces, vertices
-
Methods inherited from class math.geom2d.curve.AbstractContinuousCurve2D
asAwtShape
-
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface math.geom2d.curve.SmoothCurve2D
normal
-
Methods inherited from interface math.geom2d.curve.ContinuousCurve2D
leftTangent, rightTangent, smoothPieces
-
Methods inherited from interface math.geom2d.curve.Curve2D
asAwtShape, isSingular, singularPoints, vertices
-
-
-
-
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 semi 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
-
create
public static Ellipse2D create(Point2D focus1, Point2D focus2, double chord)
Create a new Ellipse by specifying the two focii, and the length of the chord. The chord equals the sum of distances between a point of the ellipse and each focus.- Parameters:
focus1- the first focusfocus2- the second focuschord- the sum of distances to focii- Returns:
- a new instance of Ellipse2D
-
create
@Deprecated public static Ellipse2D create(Point2D center, double l1, double l2)
Deprecated. since 0.11.1Main constructor: define center by a point plus major and minor semi axis
-
create
@Deprecated public static Ellipse2D create(Point2D center, double l1, double l2, double theta)
Deprecated. since 0.11.1Define center by point, major and minor semi axis lengths, and orientation angle.
-
create
public static Ellipse2D create(Point2D center, double l1, double l2, double theta, boolean direct)
Define center by point, major and minor semi axis lengths, orientation angle, and boolean flag for direct ellipse.
-
create
@Deprecated public static Ellipse2D create(java.awt.geom.Ellipse2D ellipse)
Deprecated. since 0.11.1Constructs an ellipse from the java.awt.geom class for ellipse.
-
reduceCentered
public static Ellipse2D reduceCentered(double[] coefs)
Creates a new Ellipse by reducing the conic coefficients, assuming conic type is ellipse, and ellipse is centered.- Parameters:
coefs- an array of double with at least 3 coefficients containing coefficients for x^2, xy, and y^2 factors.- Returns:
- the Ellipse2D corresponding to given coefficients
-
transformCentered
public static Ellipse2D transformCentered(Ellipse2D ellipse, AffineTransform2D trans)
Transform an ellipse, by supposing both the ellipse is centered and the transform has no translation part.- Parameters:
ellipse- an ellipsetrans- an affine transform- Returns:
- the transformed ellipse, centered around origin
-
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
-
projectedVector
public Vector2D projectedVector(Point2D point, double eMax)
Compute projection of a point onto an ellipse. Return the polar vector representing the translation from pointpoint to its projection on the ellipse, with the direction parallel to the local normal to the ellipse. The parameterrhoof 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
-
parallel
public Ellipse2D parallel(double d)
Return the parallel ellipse located at a distance d from this ellipse. For direct ellipse, distance is positive outside of the ellipse, and negative inside
-
isDirect
public boolean isDirect()
Returns true if ellipse has a direct orientation.- Specified by:
isDirectin interfaceEllipseShape2D
-
isCircle
public boolean isCircle()
Returns true if this ellipse is similar to a circle, i.e. has same length for both r1 and r2.- Specified by:
isCirclein interfaceEllipseShape2D
-
semiMajorAxisLength
public double semiMajorAxisLength()
Returns the length of the major semi-axis of the ellipse.
-
semiMinorAxisLength
public double semiMinorAxisLength()
Returns the length of the minor semi-axis of the ellipse.
-
center
public Point2D center()
Returns center of the ellipse.- Specified by:
centerin interfaceEllipseShape2D
-
focus1
public Point2D focus1()
Return the first focus. It is defined as the first focus on the Major axis, in the direction given by angle theta.
-
focus2
public Point2D focus2()
Returns the second focus. It is defined as the second focus on the Major axis, in the direction given by angle theta.
-
vector1
public Vector2D vector1()
Returns the first direction vector of the ellipse, in the direction of the major axis.
-
vector2
public Vector2D vector2()
Returns the second direction vector of the ellipse, in the direction of the minor axis.
-
angle
public double angle()
Returns the angle of the ellipse first axis with the Ox axis.
-
conicType
public Conic2D.Type conicType()
-
conicCoefficients
public double[] conicCoefficients()
Returns the conic coefficients of the ellipse. Algorithm taken from http://tog.acm.org/GraphicsGems/gemsv/ch2-6/conmat.c- Specified by:
conicCoefficientsin interfaceConic2D
-
eccentricity
public double eccentricity()
Computes eccentricity of ellipse, depending on the lengths of the semi-axes. Eccentricity is 0 for a circle (r1==r2), and tends to 1 when ellipse elongates.- Specified by:
eccentricityin interfaceConic2D
-
domain
public Domain2D domain()
Description copied from interface:Boundary2DReturns the domain delimited by this boundary.- Specified by:
domainin interfaceBoundary2D- Returns:
- the domain delimited by this boundary
-
fill
public void fill(java.awt.Graphics2D g2)
Description copied from interface:Boundary2DFills the interior of the boundary, using the Graphics current Paint.- Specified by:
fillin interfaceBoundary2D- Parameters:
g2- the Graphics to fill on
-
windingAngle
public double windingAngle(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:
windingAnglein interfaceOrientedCurve2D- Parameters:
point- a point of the plane- Returns:
- a signed angle
-
isInside
public boolean isInside(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:
isInsidein interfaceBoundary2D- Specified by:
isInsidein interfaceOrientedCurve2D- Parameters:
point- a point in the plane- Returns:
- true if the point is on the left side of the curve.
-
signedDistance
public double signedDistance(Point2D point)
Returns an approximation of the signed distance to the ellipse. In the current implementation, the ellipse is converted to a polyline.- Specified by:
signedDistancein interfaceOrientedCurve2D- Parameters:
point- a point of the plane- Returns:
- the signed distance to the curve
-
signedDistance
public double signedDistance(double x, double y)Description copied from interface:OrientedCurve2DThe same as distanceSigned(Point2D), but by passing 2 double as arguments.- Specified by:
signedDistancein interfaceOrientedCurve2D- Parameters:
x- x-coord of a pointy- y-coord of a point- Returns:
- the signed distance of the point (x,y) to the curve
-
tangent
public Vector2D tangent(double t)
Description copied from interface:SmoothCurve2DReturns the tangent of the curve at the given position.- Specified by:
tangentin interfaceSmoothCurve2D- Parameters:
t- a position on the curve- Returns:
- the tangent vector computed for position t
- See Also:
SmoothCurve2D.normal(double)
-
curvature
public double curvature(double t)
Returns the curvature of the ellipse.- Specified by:
curvaturein interfaceContinuousCurve2D- Parameters:
t- the position on the curve- Returns:
- the curvature of the curve for position t
-
isClosed
public boolean isClosed()
Returns true, as an ellipse is always closed.- Specified by:
isClosedin interfaceContinuousCurve2D
-
asPolyline
public LinearRing2D asPolyline(int n)
Description copied from class:AbstractContinuousCurve2DConverts this continuous curve to an instance of LinearCurve2D with the given number of edges. Returns either an instance of Polyline2D or LinearRing2D, depending on the curve is closed or not. This method can be overridden to return the correct type.- Specified by:
asPolylinein interfaceContinuousCurve2D- Overrides:
asPolylinein classAbstractContinuousCurve2D- Parameters:
n- the number of line segments- Returns:
- a polyline with
nline segments. - See Also:
ContinuousCurve2D.asPolyline(int)
-
isBounded
public boolean isBounded()
Always returns true.
-
isEmpty
public boolean isEmpty()
Always returns false.
-
t0
public double t0()
Returns the parameter of the first point of the ellipse, set to 0.
-
getT0
@Deprecated public double getT0()
Deprecated. replaced by t0() (since 0.11.1).
-
t1
public double t1()
Returns the parameter of the last point of the ellipse, set to 2*PI.
-
getT1
@Deprecated public double getT1()
Deprecated. replaced by t1() (since 0.11.1).
-
point
public Point2D point(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*PI.
-
firstPoint
public Point2D firstPoint()
Returns the first point of the ellipse, which is the same as the last point.- Specified by:
firstPointin interfaceCurve2D- Overrides:
firstPointin classAbstractContinuousCurve2D- Returns:
- the first point of the ellipse
- See Also:
Curve2D.t0(),Curve2D.point(double)
-
lastPoint
public Point2D lastPoint()
Returns the last point of the ellipse, which is the same as the first point.- Specified by:
lastPointin interfaceCurve2D- Overrides:
lastPointin classAbstractContinuousCurve2D- Returns:
- the last point of the ellipse.
- See Also:
Curve2D.t1(),Curve2D.point(double)
-
position
public double position(Point2D point)
Description copied from interface:Curve2DComputes the position of the point on the curve. If the point does not belong to the curve, return Double.NaN. It is complementary to thepoint(double)method.- Specified by:
positionin interfaceCurve2D- Parameters:
point- a point belonging to the curve- Returns:
- the position of the point on the curve
- See Also:
Curve2D.point(double)
-
project
public double project(Point2D point)
Computes the approximate projection position of the point on the ellipse. The ellipse is first converted to a unit circle, then the angular position of the point is computed in the transformed basis.
-
reverse
public Ellipse2D reverse()
Returns the ellipse with same center and same radius, but with the other orientation.- Specified by:
reversein interfaceConic2D- Specified by:
reversein interfaceEllipseShape2D- Specified by:
reversein interfaceContinuousCurve2D- Specified by:
reversein interfaceCurve2D- Specified by:
reversein interfaceSmoothCurve2D- Specified by:
reversein interfaceBoundary2D- Specified by:
reversein interfaceContinuousOrientedCurve2D- Specified by:
reversein interfaceContour2D- Specified by:
reversein interfaceOrientedCurve2D- Specified by:
reversein interfaceSmoothContour2D- Specified by:
reversein interfaceSmoothOrientedCurve2D
-
continuousCurves
public java.util.Collection<? extends Ellipse2D> continuousCurves()
Description copied from interface:Curve2DReturns the collection of continuous curves which constitute this curve.- Specified by:
continuousCurvesin interfaceEllipseShape2D- Specified by:
continuousCurvesin interfaceCurve2D- Specified by:
continuousCurvesin interfaceBoundary2D- Overrides:
continuousCurvesin classAbstractContinuousCurve2D- Returns:
- a collection of continuous curves.
-
subCurve
public EllipseArc2D subCurve(double t0, double t1)
return a new EllipseArc2D.- Specified by:
subCurvein interfaceContinuousCurve2D- Specified by:
subCurvein interfaceCurve2D- Specified by:
subCurvein interfaceSmoothCurve2D- Specified by:
subCurvein interfaceContinuousOrientedCurve2D- Specified by:
subCurvein interfaceSmoothOrientedCurve2D- Parameters:
t0- position of the start of the sub-curvet1- position of the end of the sub-curve- Returns:
- the portion of original curve comprised between t0 and t1.
-
distance
public double distance(Point2D point)
Computes distance using a polyline approximation.
-
distance
public double distance(double x, double y)Description copied from interface:Shape2DReturns 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.
-
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:
clipin interfaceConic2D- Specified by:
clipin interfaceContinuousCurve2D- Specified by:
clipin interfaceCurve2D- Specified by:
clipin interfaceSmoothCurve2D- Specified by:
clipin interfaceContinuousOrientedCurve2D- Specified by:
clipin interfaceOrientedCurve2D- Specified by:
clipin interfaceSmoothOrientedCurve2D- Specified by:
clipin interfaceShape2D- Parameters:
box- the clipping box- Returns:
- the clipped shape
-
boundingBox
public Box2D boundingBox()
Return more precise bounds for the ellipse. Return an instance of Box2D.- Specified by:
boundingBoxin interfaceShape2D- Returns:
- the bounding box of the shape.
-
intersections
public java.util.Collection<Point2D> intersections(LinearShape2D 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:
intersectionsin interfaceCurve2D
-
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. The resulting ellipse is direct if this ellipse and the transform are either both direct or both indirect.- Specified by:
transformin interfaceConic2D- Specified by:
transformin interfaceEllipseShape2D- Specified by:
transformin interfaceContinuousCurve2D- Specified by:
transformin interfaceCurve2D- Specified by:
transformin interfaceSmoothCurve2D- Specified by:
transformin interfaceBoundary2D- Specified by:
transformin interfaceContinuousOrientedCurve2D- Specified by:
transformin interfaceContour2D- Specified by:
transformin interfaceOrientedCurve2D- Specified by:
transformin interfaceSmoothContour2D- Specified by:
transformin interfaceSmoothOrientedCurve2D- Specified by:
transformin interfaceShape2D- Parameters:
trans- an affine transform- Returns:
- the transformed shape
-
contains
public boolean contains(Point2D p)
Returns true if the point p lies on the ellipse, with precision given by Shape2D.ACCURACY.
-
contains
public boolean contains(double x, double y)Returns true if the point (x, y) lies on the ellipse, with precision given by Shape2D.ACCURACY.
-
getGeneralPath
public java.awt.geom.GeneralPath getGeneralPath()
-
appendPath
public java.awt.geom.GeneralPath appendPath(java.awt.geom.GeneralPath path)
Add the path of the ellipse to the given path.- Specified by:
appendPathin interfaceContinuousCurve2D- Parameters:
path- the path to be completed- Returns:
- the completed path
-
draw
public void draw(java.awt.Graphics2D g2)
Description copied from interface:Curve2DDraws the curve on the given Graphics2D object.
-
almostEquals
public boolean almostEquals(GeometricObject2D obj, double eps)
Description copied from interface:GeometricObject2DChecks if the two objects are similar up to a given threshold value. This method can be used to compare the results of geometric computations, that introduce errors due to numerical computations.- Specified by:
almostEqualsin interfaceGeometricObject2D- Parameters:
obj- the object to compareeps- a threshold value, for example the minimal coordinate difference- Returns:
- true if both object have the same value up to the threshold
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
clone
@Deprecated public Ellipse2D clone()
Deprecated. use copy constructor instead (0.11.2)- Specified by:
clonein interfaceCurve2D- Specified by:
clonein classAbstractSmoothCurve2D
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-
DMelt 3.0 © DataMelt by jWork.ORG