Package com.irurueta.geometry
Class Ellipse
java.lang.Object
com.irurueta.geometry.Ellipse
- All Implemented Interfaces:
Serializable
This class defines an ellipse.
This class uses formulas as defined at:
https://en.wikipedia.org/wiki/Ellipse
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Point2DCenter of ellipse.static final doubleConstant defining default threshold value used when none is provided.static final doubleConstant defining minimum allowed threshold.private doubleRotation angle.private doubleSemi-major axis length (a).private doubleSemi-minor axis length (b). -
Constructor Summary
ConstructorsConstructorDescriptionEllipse()Empty constructor.Ellipse(double a, double b, double c, double d, double e, double f) Constructor setting parameters of canonical equation of an ellipse, which is: a*x^2 + b*x*y + c*y^2 + d*x + e*y + f = 0Ellipse(double a, double b, double c, double d, double e, double f, double threshold) Constructor setting parameters of canonical equation of an ellipse, which is: a*x^2 + b*x*y + c*y^2 + d*x + e*y + f = 0Constructor.Constructor.Constructor.Ellipse(Point2D center, double semiMajorAxis, double semiMinorAxis, Rotation2D rotation) Constructor.Constructor from 2 points, ellipse center and rotation.Constructor from 5 points.Ellipse(Point2D point1, Point2D point2, Point2D point3, Point2D point4, Point2D point5, double threshold) Constructor from 5 points. -
Method Summary
Modifier and TypeMethodDescriptiondoublegetA()Gets parameter A of canonical ellipse equation: A*x^2 + B*x*y + C*y^2 + D*x + E*y + F = 0doublegetArea()Returns area of this ellipse.doublegetB()Gets parameter B of canonical ellipse equation: A*x^2 + B*x*y + C*y^2 + D*x + E*y + F = 0doublegetC()Gets parameter C of canonical ellipse equation: A*x^2 + B*x*y + C*y^2 + D*x + E*y + F = 0Returns center of ellipse.doublegetCurvature(Point2D point) Gets curvature of ellipse at provided point.doublegetD()Gets parameter D of canonical ellipse equation: A*x^2 + B*x*y + C*y^2 + D*x + E*y + F = 0doublegetE()Gets parameter E of canonical ellipse equation: A*x^2 + B*x*y + C*y^2 + D*x + E*y + F = 0doubleGets eccentricity of ellipsis.doublegetF()Gets parameter F of canonical ellipse equation: A*x^2 + B*x*y + C*y^2 + D*x + E*y + F = 0doublegetFocus()Gets focus distance of ellipse.Gets 1st focus point.voidgetFocusPoint1(Point2D focusPoint1) Gets 1st focus point.Gets 2nd focus point.voidgetFocusPoint2(Point2D focusPoint2) Gets 2nd focus point.doubleReturns perimeter of this ellipse.Gets 2D rotation.doubleGets rotation angle expressed in radians.doubleGets semi-major axis length.double[]Gets semi major axis x,y coordinates.voidgetSemiMajorAxisCoordinates(double[] coords) Gets semi major axis x,y coordinates.doubleGets semi-minor axis length.double[]Gets semi minor axis x,y coordinates.voidgetSemiMinorAxisCoordinates(double[] coords) Gets semi minor axis x,y coordinates.getTangentLineAt(Point2D point) Returns a line tangent to this ellipse at provided point.getTangentLineAt(Point2D point, double threshold) Returns a line tangent to this ellipse at provided point.booleanDetermines if provided point is inside this circle or not.booleanDetermines if provided point is inside this ellipse or not up to a certain threshold.booleanDetermines whether provided point lies at ellipse boundary or not.booleanDetermines whether provided point lies at ellipse boundary or not up to a certain threshold.voidsetA(double a) Sets parameter A of canonical ellipse equation.voidsetB(double b) Sets parameter B of canonical ellipse equation: A*x^2 + B*x*y + C*y^2 + D*x + E*y + F = 0voidsetC(double c) Sets parameter C of canonical ellipse equation: A*x^2 + B*x*y + C*y^2 + D*x + E*y + F = 0voidSets center of ellipse.final voidsetCenterAxesAndRotation(Point2D center, double semiMajorAxis, double semiMinorAxis, double rotationAngle) Sets ellipse parameters.final voidsetCenterAxesAndRotation(Point2D center, double semiMajorAxis, double semiMinorAxis, Rotation2D rotation) Sets ellipse parameters.voidsetD(double d) Sets parameter D of canonical ellipse equation: A*x^2 + B*x*y + C*y^2 + D*x + E*y + F = 0voidsetE(double e) Sets parameter E of canonical ellipse equation: A*x^2 + B*x*y + C*y^2 + D*x + E*y + F = 0voidsetF(double f) Sets parameter F of canonical ellipse equation.voidsetFocusPoints(Point2D focusPoint1, Point2D focusPoint2, boolean keepSemiMinorAxis) Sets focus points.final voidsetFromCircle(Circle circle) Sets parameters of this ellipse from a circle.final voidsetFromConic(Conic conic) Set parameters of this circle from a valid conic corresponding to a circle.final voidsetParameters(double a, double b, double c, double d, double e, double f) Sets parameters of canonical equation of an ellipse, which is: a*x^2 + b*x*y + c*y^2 + d*x + e*y + f = 0final voidsetParameters(double a, double b, double c, double d, double e, double f, double threshold) Sets parameters of canonical equation of an ellipse, which is: a*x^2 + b*x*y + c*y^2 + d*x + e*y + f = 0final voidsetParametersFromPoints(Point2D point1, Point2D point2, Point2D point3, Point2D point4, Point2D point5) Sets parameters from 5 points.final voidsetParametersFromPoints(Point2D point1, Point2D point2, Point2D point3, Point2D point4, Point2D point5, double threshold) Sets parameters from 5 points.final voidsetParametersFromPointsCenterAndRotation(Point2D point1, Point2D point2, Point2D center, double theta) Sets parameters from 2 points, ellipse center and rotation.voidsetRotation(Rotation2D rotation) Sets 2D rotation.voidsetRotationAngle(double rotationAngle) Sets rotation angle expressed in radians.voidsetSemiMajorAxis(double semiMajorAxis) Sets semi-major axis length.voidsetSemiMajorAxisCoordinates(double[] coords) Sets semi major axis coordinates.voidsetSemiMinorAxis(double semiMinorAxis) Sets semi-minor axis length.voidsetSemiMinorAxisCoordinates(double[] coords) Sets semi minor axis coordinates.voidtangentLineAt(Point2D point, Line2D line, double threshold) Computes a line tangent to this circle at provided point.toConic()Converts this circle into a conic.
-
Field Details
-
DEFAULT_THRESHOLD
public static final double DEFAULT_THRESHOLDConstant defining default threshold value used when none is provided.- See Also:
-
MIN_THRESHOLD
public static final double MIN_THRESHOLDConstant defining minimum allowed threshold.- See Also:
-
center
Center of ellipse. -
semiMajorAxis
private double semiMajorAxisSemi-major axis length (a). -
semiMinorAxis
private double semiMinorAxisSemi-minor axis length (b). -
rotationAngle
private double rotationAngleRotation angle.
-
-
Constructor Details
-
Ellipse
public Ellipse()Empty constructor. Creates an ellipse equal to a circle located at space origin (0,0) with radius 1.0. -
Ellipse
Constructor.- Parameters:
center- center of ellipse.semiMajorAxis- semi-major axis length.semiMinorAxis- semi-minor axis length.rotationAngle- rotation angle expressed in radians.
-
Ellipse
Constructor.- Parameters:
center- center of ellipse.semiMajorAxis- semi-major axis length.semiMinorAxis- semi-minor axis length.rotation- 2D rotation.
-
Ellipse
public Ellipse(Point2D point1, Point2D point2, Point2D center, double theta) throws ColinearPointsException Constructor from 2 points, ellipse center and rotation.- Parameters:
point1- 1st point.point2- 2nd point.center- center of ellipse.theta- rotation angle expressed in radians.- Throws:
ColinearPointsException- if points are in a co-linear or degenerate configuration.
-
Ellipse
public Ellipse(Point2D point1, Point2D point2, Point2D point3, Point2D point4, Point2D point5) throws ColinearPointsException Constructor from 5 points.- Parameters:
point1- 1st point.point2- 2nd point.point3- 3rd point.point4- 4th point.point5- 5th point.- Throws:
ColinearPointsException- if points are in a co-linear or degenerate configuration.
-
Ellipse
public Ellipse(Point2D point1, Point2D point2, Point2D point3, Point2D point4, Point2D point5, double threshold) throws ColinearPointsException Constructor from 5 points.- Parameters:
point1- 1st point.point2- 2nd point.point3- 3rd point.point4- 4th point.point5- 5th point.threshold- threshold to determine whether points form an ellipse. This is usually a very small value- Throws:
ColinearPointsException- if points are in a co-linear or degenerate configuration.
-
Ellipse
public Ellipse(double a, double b, double c, double d, double e, double f) Constructor setting parameters of canonical equation of an ellipse, which is: a*x^2 + b*x*y + c*y^2 + d*x + e*y + f = 0- Parameters:
a- a parameter.b- b parameter.c- c parameter.d- d parameter.e- e parameter.f- f parameter.- Throws:
IllegalArgumentException- if parameters do not follow b^2 - 4*a*c < 0.0
-
Ellipse
public Ellipse(double a, double b, double c, double d, double e, double f, double threshold) Constructor setting parameters of canonical equation of an ellipse, which is: a*x^2 + b*x*y + c*y^2 + d*x + e*y + f = 0- Parameters:
a- a parameter.b- b parameter.c- c parameter.d- d parameter.e- e parameter.f- f parameter.threshold- threshold to determine whether parameters are valid due to machine precision.- Throws:
IllegalArgumentException- if parameters do not follow b^2 - 4*A*c < threshold
-
Ellipse
Constructor.- Parameters:
conic- conic to build ellipse from.- Throws:
IllegalArgumentException- if provided conic is not an ellipse.
-
Ellipse
Constructor.- Parameters:
circle- a circle to set parameters from.
-
-
Method Details
-
getCenter
Returns center of ellipse.- Returns:
- center of ellipse.
-
setCenter
Sets center of ellipse.- Parameters:
center- center of ellipse.- Throws:
NullPointerException- raised if provided center is null.
-
getSemiMajorAxis
public double getSemiMajorAxis()Gets semi-major axis length.- Returns:
- semi-major axis length.
-
setSemiMajorAxis
public void setSemiMajorAxis(double semiMajorAxis) Sets semi-major axis length.- Parameters:
semiMajorAxis- semi-major axis length.
-
getSemiMinorAxis
public double getSemiMinorAxis()Gets semi-minor axis length.- Returns:
- semi-minor axis length.
-
setSemiMinorAxis
public void setSemiMinorAxis(double semiMinorAxis) Sets semi-minor axis length.- Parameters:
semiMinorAxis- semi-minor axis length.
-
getRotationAngle
public double getRotationAngle()Gets rotation angle expressed in radians.- Returns:
- rotation angle expressed in radians.
-
setRotationAngle
public void setRotationAngle(double rotationAngle) Sets rotation angle expressed in radians.- Parameters:
rotationAngle- rotation angle expressed in radians.
-
getRotation
Gets 2D rotation.- Returns:
- 2D rotation.
-
setRotation
Sets 2D rotation.- Parameters:
rotation- 2D rotation to be set.
-
getA
public double getA()Gets parameter A of canonical ellipse equation: A*x^2 + B*x*y + C*y^2 + D*x + E*y + F = 0- Returns:
- parameter A.
-
setA
public void setA(double a) Sets parameter A of canonical ellipse equation. A*x^2 + B*x*y + C*y^2 + D*x + E*y + F = 0- Parameters:
a- parameter A to be set.
-
getB
public double getB()Gets parameter B of canonical ellipse equation: A*x^2 + B*x*y + C*y^2 + D*x + E*y + F = 0- Returns:
- parameter B.
-
setB
public void setB(double b) Sets parameter B of canonical ellipse equation: A*x^2 + B*x*y + C*y^2 + D*x + E*y + F = 0- Parameters:
b- parameter B to be set.
-
getC
public double getC()Gets parameter C of canonical ellipse equation: A*x^2 + B*x*y + C*y^2 + D*x + E*y + F = 0- Returns:
- parameter C.
-
setC
public void setC(double c) Sets parameter C of canonical ellipse equation: A*x^2 + B*x*y + C*y^2 + D*x + E*y + F = 0- Parameters:
c- parameter C to be set.
-
getD
public double getD()Gets parameter D of canonical ellipse equation: A*x^2 + B*x*y + C*y^2 + D*x + E*y + F = 0- Returns:
- parameter D.
-
setD
public void setD(double d) Sets parameter D of canonical ellipse equation: A*x^2 + B*x*y + C*y^2 + D*x + E*y + F = 0- Parameters:
d- parameter D to be set.
-
getE
public double getE()Gets parameter E of canonical ellipse equation: A*x^2 + B*x*y + C*y^2 + D*x + E*y + F = 0- Returns:
- parameter E.
-
setE
public void setE(double e) Sets parameter E of canonical ellipse equation: A*x^2 + B*x*y + C*y^2 + D*x + E*y + F = 0- Parameters:
e- parameter E to be set.
-
getF
public double getF()Gets parameter F of canonical ellipse equation: A*x^2 + B*x*y + C*y^2 + D*x + E*y + F = 0- Returns:
- parameter F.
-
setF
public void setF(double f) Sets parameter F of canonical ellipse equation. A*x^2 + B*x*y + C*y^2 + D*x + E*y + F = 0- Parameters:
f- parameter F to be set.
-
setCenterAxesAndRotation
public final void setCenterAxesAndRotation(Point2D center, double semiMajorAxis, double semiMinorAxis, double rotationAngle) Sets ellipse parameters.- Parameters:
center- center of ellipse.semiMajorAxis- semi-major axis length.semiMinorAxis- semi-minor axis length.rotationAngle- rotation angle expressed in radians.
-
setCenterAxesAndRotation
public final void setCenterAxesAndRotation(Point2D center, double semiMajorAxis, double semiMinorAxis, Rotation2D rotation) Sets ellipse parameters.- Parameters:
center- center of ellipse.semiMajorAxis- semi-major axis length.semiMinorAxis- semi-minor axis length.rotation- 2D rotation.
-
setParametersFromPointsCenterAndRotation
public final void setParametersFromPointsCenterAndRotation(Point2D point1, Point2D point2, Point2D center, double theta) throws ColinearPointsException Sets parameters from 2 points, ellipse center and rotation.- Parameters:
point1- 1st point.point2- 2nd point.center- center of ellipse.theta- rotation angle expressed in radians.- Throws:
ColinearPointsException- if points are in a co-linear or degenerate configuration.
-
setParametersFromPoints
public final void setParametersFromPoints(Point2D point1, Point2D point2, Point2D point3, Point2D point4, Point2D point5) throws ColinearPointsException Sets parameters from 5 points.- Parameters:
point1- 1st point.point2- 2nd point.point3- 3rd point.point4- 4th point.point5- 5th point.- Throws:
ColinearPointsException- if points are in a co-linear or degenerate configuration.
-
setParametersFromPoints
public final void setParametersFromPoints(Point2D point1, Point2D point2, Point2D point3, Point2D point4, Point2D point5, double threshold) throws ColinearPointsException Sets parameters from 5 points.- Parameters:
point1- 1st point.point2- 2nd point.point3- 3rd point.point4- 4th point.point5- 5th point.threshold- threshold to determine whether points form an ellipse. This is usually a very small value- Throws:
ColinearPointsException- if points are in a co-linear or degenerate configuration.
-
setParameters
public final void setParameters(double a, double b, double c, double d, double e, double f) Sets parameters of canonical equation of an ellipse, which is: a*x^2 + b*x*y + c*y^2 + d*x + e*y + f = 0- Parameters:
a- a parameter.b- b parameter.c- c parameter.d- d parameter.e- e parameter.f- f parameter.- Throws:
IllegalArgumentException- if parameters do not follow b^2 - 4*a*c < 0.0.
-
setParameters
public final void setParameters(double a, double b, double c, double d, double e, double f, double threshold) Sets parameters of canonical equation of an ellipse, which is: a*x^2 + b*x*y + c*y^2 + d*x + e*y + f = 0- Parameters:
a- a parameter.b- b parameter.c- c parameter.d- d parameter.e- e parameter.f- f parameter.threshold- threshold to determine whether parameters are valid due to machine precision.- Throws:
IllegalArgumentException- if parameters do not follow b^2 - 4*A*c < threshold.
-
getFocus
public double getFocus()Gets focus distance of ellipse. Focus determines the distance respect to the center of the ellipse where the two focus points are located. The sum of the distances from any point P = P(x,y) on the ellipse to those two foci is constant and equal to the major axis length.- Returns:
- focus distance.
-
getSemiMajorAxisCoordinates
public void getSemiMajorAxisCoordinates(double[] coords) Gets semi major axis x,y coordinates.- Parameters:
coords- array where x, y coordinates of semi major axis will be stored.
-
getSemiMajorAxisCoordinates
public double[] getSemiMajorAxisCoordinates()Gets semi major axis x,y coordinates.- Returns:
- array containing x, y coordinates of semi major axis.
-
setSemiMajorAxisCoordinates
public void setSemiMajorAxisCoordinates(double[] coords) Sets semi major axis coordinates. This method updates rotation angle and semi major axis length.- Parameters:
coords- coordinates of semi major axis.
-
getSemiMinorAxisCoordinates
public void getSemiMinorAxisCoordinates(double[] coords) Gets semi minor axis x,y coordinates.- Parameters:
coords- array where x, y coordinates of semi minor axis will be stored.
-
getSemiMinorAxisCoordinates
public double[] getSemiMinorAxisCoordinates()Gets semi minor axis x,y coordinates.- Returns:
- array containing x,y coordinates of semi minor axis.
-
setSemiMinorAxisCoordinates
public void setSemiMinorAxisCoordinates(double[] coords) Sets semi minor axis coordinates. This method updates rotation angle and semi minor axis length.- Parameters:
coords- coordinates of semi minor axis.
-
getFocusPoint1
Gets 1st focus point. The sum of the distances from any point P = P(x,y) on the ellipse to this focus is constant and equal to the major axis length.- Parameters:
focusPoint1- 1st focus point.
-
getFocusPoint1
Gets 1st focus point. The sum of the distances from any point P = P(x,y) on the ellipse to this focus is constant and equal to the major axis length.- Returns:
- 1st focus point.
-
getFocusPoint2
Gets 2nd focus point. The sum of the distances from any point P = P(x,y) on the ellipse to this focus is constant and equal to the major axis length.- Parameters:
focusPoint2- 2nd focus point.
-
getFocusPoint2
Gets 2nd focus point. The sum of the distances from any point P = P(x,y) on the ellipse to this focus is constant and equal to the major axis length.- Returns:
- 2nd focus point.
-
setFocusPoints
Sets focus points.- Parameters:
focusPoint1- 1st focus point.focusPoint2- 2nd focus point.keepSemiMinorAxis- true indicates that semi-minor axis is kept, false indicates that semi-major axis is kept instead.
-
getEccentricity
public double getEccentricity()Gets eccentricity of ellipsis.- Returns:
- eccentricity of ellipsis.
-
getArea
public double getArea()Returns area of this ellipse.- Returns:
- area of this ellipse.
-
getPerimeter
public double getPerimeter()Returns perimeter of this ellipse.- Returns:
- Perimeter of this ellipse.
-
getCurvature
Gets curvature of ellipse at provided point.- Parameters:
point- point to be checked.- Returns:
- curvature of ellipse.
-
toConic
Converts this circle into a conic. Conics are a more general representation of circles.- Returns:
- A conic representing this circle
-
setFromConic
Set parameters of this circle from a valid conic corresponding to a circle.- Parameters:
conic- conic to set parameters from.- Throws:
IllegalArgumentException- if provided conic is not an ellipse.
-
setFromCircle
Sets parameters of this ellipse from a circle.- Parameters:
circle- a circle to set parameters from.
-
isInside
Determines if provided point is inside this ellipse or not up to a certain threshold. If provided threshold is positive, the ellipse behaves as if it was a larger ellipse increased by threshold amount, if provided threshold is negative, the ellipse behaves as if it was a smaller ellipse decreased by threshold amount in radius.- Parameters:
point- Point to be checked.threshold- Threshold to determine if point is inside or not.- Returns:
- True if point is considered to be inside this circle, false otherwise.
-
isInside
Determines if provided point is inside this circle or not.- Parameters:
point- Point to be checked.- Returns:
- True if point is considered to be inside this circle, false otherwise.
-
isLocus
Determines whether provided point lies at ellipse boundary or not up to a certain threshold.- Parameters:
point- Point to be checked.threshold- A small threshold to determine whether point lies at ellipse boundary.- Returns:
- True if point lies at ellipse boundary, false otherwise.
- Throws:
IllegalArgumentException- Raised if provided threshold is negative.
-
isLocus
Determines whether provided point lies at ellipse boundary or not.- Parameters:
point- Point to be checked.- Returns:
- True if point lies at ellipse boundary, false otherwise.
-
getTangentLineAt
Returns a line tangent to this ellipse at provided point. Provided point must be locus of this ellipse, otherwise a NotLocusException will be thrown.- Parameters:
point- a locus point of this ellipse.- Returns:
- a 2D line tangent to this ellipse at provided point.
- Throws:
NotLocusException- if provided point is not locus of this ellipse up to DEFAULT_THRESHOLD.
-
getTangentLineAt
Returns a line tangent to this ellipse at provided point. Provided point must be locus of this ellipse, otherwise a NotLocusException will be thrown.- Parameters:
point- a locus point of this circle.threshold- threshold to determine if provided point is locus.- Returns:
- a 2D line tangent to this circle at provided point.
- Throws:
NotLocusException- if provided point is not locus of this circle up to provided threshold.IllegalArgumentException- if provided threshold is negative.
-
tangentLineAt
Computes a line tangent to this circle at provided point. Provided point must be locus of this circle, otherwise a NotLocusException will be thrown.- Parameters:
point- a locus point of this circle.line- instance of a 2D line where result will be stored.threshold- threshold to determine if provided point is locus.- Throws:
NotLocusException- if provided point is not locus of this circle up to provided threshold.IllegalArgumentException- if provided threshold is negative.
-