Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
Geom::Ellipse Class Reference

Set of points with a constant sum of distances from two foci. More...

#include <ellipse.h>

Inheritance diagram for Geom::Ellipse:

Public Member Functions

 Ellipse ()
 
 Ellipse (Point const &c, Point const &r, Coord angle)
 
 Ellipse (Coord cx, Coord cy, Coord rx, Coord ry, Coord angle)
 
 Ellipse (double A, double B, double C, double D, double E, double F)
 
 Ellipse (Geom::Circle const &c)
 Construct ellipse from a circle.
 
void set (Point const &c, Point const &r, Coord angle)
 Set center, rays and angle.
 
void set (Coord cx, Coord cy, Coord rx, Coord ry, Coord a)
 Set center, rays and angle as constituent values.
 
void setCoefficients (double A, double B, double C, double D, double E, double F)
 Set an ellipse by solving its implicit equation.
 
void setCenter (Point const &p)
 Set the center.
 
void setCenter (Coord cx, Coord cy)
 Set the center by coordinates.
 
void setRays (Point const &p)
 Set both rays of the ellipse.
 
void setRays (Coord x, Coord y)
 Set both rays of the ellipse as coordinates.
 
void setRay (Coord r, Dim2 d)
 Set one of the rays of the ellipse.
 
void setRotationAngle (Angle a)
 Set the angle the X ray makes with the +X axis.
 
Point center () const
 
Coord center (Dim2 d) const
 
Point rays () const
 Get both rays as a point.
 
Coord ray (Dim2 d) const
 Get one ray of the ellipse.
 
Angle rotationAngle () const
 Get the angle the X ray makes with the +X axis.
 
Point initialPoint () const
 Get the point corresponding to the +X ray of the ellipse.
 
Point finalPoint () const
 Get the point corresponding to the +X ray of the ellipse.
 
void fit (std::vector< Point > const &points)
 Create an ellipse passing through the specified points At least five points have to be specified.
 
EllipticalArcarc (Point const &ip, Point const &inner, Point const &fp)
 Create an elliptical arc from a section of the ellipse.
 
Ellipse canonicalForm () const
 Return an ellipse with less degrees of freedom.
 
void makeCanonical ()
 
Affine unitCircleTransform () const
 Compute the transform that maps the unit circle to this ellipse.
 
Affine inverseUnitCircleTransform () const
 Compute the transform that maps this ellipse to the unit circle.
 
LineSegment majorAxis () const
 
LineSegment minorAxis () const
 
LineSegment semimajorAxis (int sign=1) const
 
LineSegment semiminorAxis (int sign=1) const
 
LineSegment axis (Dim2 d) const
 
LineSegment semiaxis (Dim2 d, int sign=1) const
 
Rect boundsExact () const
 Get the tight-fitting bounding box of the ellipse.
 
Rect boundsFast () const
 Get a fast to compute bounding box which contains the ellipse.
 
std::vector< double > coefficients () const
 Get the coefficients of the ellipse's implicit equation.
 
void coefficients (Coord &A, Coord &B, Coord &C, Coord &D, Coord &E, Coord &F) const
 
Point pointAt (Coord t) const
 Evaluate a point on the ellipse.
 
Coord valueAt (Coord t, Dim2 d) const
 Evaluate a single coordinate of a point on the ellipse.
 
Coord timeAt (Point const &p) const
 Find the time value of a point on an ellipse.
 
Point unitTangentAt (Coord t) const
 Get the value of the derivative at time t normalized to unit length.
 
bool contains (Point const &p) const
 Check whether the ellipse contains the given point.
 
std::vector< ShapeIntersectionintersect (Line const &line) const
 Compute intersections with an infinite line.
 
std::vector< ShapeIntersectionintersect (LineSegment const &seg) const
 Compute intersections with a line segment.
 
std::vector< ShapeIntersectionintersect (Ellipse const &other) const
 Compute intersections with another ellipse.
 
std::vector< ShapeIntersectionintersect (D2< Bezier > const &other) const
 Compute intersections with a 2D Bezier polynomial.
 
Ellipseoperator*= (Translate const &t)
 
Ellipseoperator*= (Scale const &s)
 
Ellipseoperator*= (Zoom const &z)
 
Ellipseoperator*= (Rotate const &r)
 
Ellipseoperator*= (Affine const &m)
 
bool operator== (Ellipse const &other) const
 Compare ellipses for exact equality.
 

Private Attributes

Point _center
 
Point _rays
 
Angle _angle
 

Related Symbols

(Note that these are not member symbols.)

bool are_near (Ellipse const &a, Ellipse const &b, Coord precision=EPSILON)
 Test whether two ellipses are approximately the same.
 
std::ostream & operator<< (std::ostream &out, Ellipse const &e)
 Outputs ellipse data, useful for debugging.
 

Detailed Description

Set of points with a constant sum of distances from two foci.

An ellipse can be specified in several ways. Internally, 2Geom uses the SVG style representation: center, rays and angle between the +X ray and the +X axis. Another popular way is to use an implicit equation, which is as follows: \(Ax^2 + Bxy + Cy^2 + Dx + Ey + F = 0\)

Definition at line 60 of file ellipse.h.

Constructor & Destructor Documentation

◆ Ellipse() [1/5]

Geom::Ellipse::Ellipse ( )
inline

Definition at line 73 of file ellipse.h.

◆ Ellipse() [2/5]

Geom::Ellipse::Ellipse ( Point const &  c,
Point const &  r,
Coord  angle 
)
inline

Definition at line 74 of file ellipse.h.

◆ Ellipse() [3/5]

Geom::Ellipse::Ellipse ( Coord  cx,
Coord  cy,
Coord  rx,
Coord  ry,
Coord  angle 
)
inline

Definition at line 79 of file ellipse.h.

◆ Ellipse() [4/5]

Geom::Ellipse::Ellipse ( double  A,
double  B,
double  C,
double  D,
double  E,
double  F 
)
inline

Definition at line 84 of file ellipse.h.

References D, and setCoefficients().

◆ Ellipse() [5/5]

Geom::Ellipse::Ellipse ( Geom::Circle const &  c)

Construct ellipse from a circle.

Definition at line 42 of file ellipse.cpp.

Member Function Documentation

◆ arc()

EllipticalArc * Geom::Ellipse::arc ( Point const &  ip,
Point const &  inner,
Point const &  fp 
)

Create an elliptical arc from a section of the ellipse.

This is mainly useful to determine the flags of the new arc. The passed points should lie on the ellipse, otherwise the results will be undefined.

Parameters
ipInitial point of the arc
innerPoint in the middle of the arc, used to pick one of two possibilities
fpFinal point of the arc
Returns
Newly allocated arc, delete when no longer used

Definition at line 226 of file ellipse.cpp.

References _center, Geom::cross(), inner(), ray(), rotationAngle(), Geom::sgn(), Geom::X, and Geom::Y.

Referenced by Geom::Circle::arc(), and TEST().

◆ axis()

LineSegment Geom::Ellipse::axis ( Dim2  d) const

Definition at line 127 of file ellipse.cpp.

References Geom::Curve::transform(), and unitCircleTransform().

Referenced by majorAxis(), minorAxis(), and timeAt().

◆ boundsExact()

Rect Geom::Ellipse::boundsExact ( ) const

Get the tight-fitting bounding box of the ellipse.

Definition at line 146 of file ellipse.cpp.

References unitCircleTransform(), Geom::X, and Geom::Y.

Referenced by Geom::EllipticalArc::boundsExact(), and TEST().

◆ boundsFast()

Rect Geom::Ellipse::boundsFast ( ) const

Get a fast to compute bounding box which contains the ellipse.

The returned rectangle engulfs the ellipse but it may not be the smallest axis-aligned rectangle with this property.

Definition at line 162 of file ellipse.cpp.

References _center, ray(), Geom::X, and Geom::Y.

Referenced by intersect(), intersect(), and TEST().

◆ canonicalForm()

Ellipse Geom::Ellipse::canonicalForm ( ) const

Return an ellipse with less degrees of freedom.

The canonical form always has the angle less than \(\frac{\pi}{2}\), and zero if the rays are equal (i.e. the ellipse is a circle).

Definition at line 335 of file ellipse.cpp.

References result.

Referenced by operator==().

◆ center() [1/2]

◆ center() [2/2]

Coord Geom::Ellipse::center ( Dim2  d) const
inline

Definition at line 120 of file ellipse.h.

References _center.

◆ coefficients() [1/2]

std::vector< double > Geom::Ellipse::coefficients ( ) const

Get the coefficients of the ellipse's implicit equation.

Definition at line 173 of file ellipse.cpp.

References c, and coefficients().

Referenced by coefficients(), intersect(), intersect(), intersect(), and operator*=().

◆ coefficients() [2/2]

void Geom::Ellipse::coefficients ( Coord A,
Coord B,
Coord C,
Coord D,
Coord E,
Coord F 
) const

Definition at line 180 of file ellipse.cpp.

References _angle, center(), D, ray(), Geom::sincos(), Geom::X, and Geom::Y.

◆ contains()

bool Geom::Ellipse::contains ( Point const &  p) const

Check whether the ellipse contains the given point.

Definition at line 406 of file ellipse.cpp.

References inverseUnitCircleTransform(), and Geom::Point::length().

Referenced by TEST_F(), and Geom::EllipticalArc::winding().

◆ finalPoint()

Point Geom::Ellipse::finalPoint ( ) const
inline

Get the point corresponding to the +X ray of the ellipse.

Definition at line 130 of file ellipse.h.

References initialPoint().

◆ fit()

void Geom::Ellipse::fit ( std::vector< Point > const &  points)

Create an ellipse passing through the specified points At least five points have to be specified.

Definition at line 206 of file ellipse.cpp.

References Geom::NL::LFMEllipse::instance().

Referenced by Inkscape::LivePathEffect::LPEEllipse5Pts::doEffect_path(), Inkscape::LivePathEffect::LPEPts2Ellipse::genFitEllipse(), Inkscape::LivePathEffect::LPEPts2Ellipse::genPerspectiveEllipse(), and wrap_ellipse().

◆ initialPoint()

Point Geom::Ellipse::initialPoint ( ) const

Get the point corresponding to the +X ray of the ellipse.

Definition at line 101 of file ellipse.cpp.

References _angle, center(), ray(), Geom::sincos(), Geom::X, and Geom::Y.

Referenced by finalPoint().

◆ intersect() [1/4]

std::vector< ShapeIntersection > Geom::Ellipse::intersect ( D2< Bezier > const &  other) const

Compute intersections with a 2D Bezier polynomial.

Definition at line 705 of file ellipse.cpp.

References coefficients(), D, result, Geom::Bezier::roots(), timeAt(), Geom::D2< T >::valueAt(), Geom::X, and Geom::Y.

◆ intersect() [2/4]

std::vector< ShapeIntersection > Geom::Ellipse::intersect ( Ellipse const &  other) const

◆ intersect() [3/4]

◆ intersect() [4/4]

std::vector< ShapeIntersection > Geom::Ellipse::intersect ( LineSegment const &  seg) const

Compute intersections with a line segment.

Definition at line 517 of file ellipse.cpp.

References boundsFast(), Geom::BezierCurve::boundsFast(), Geom::EPSILON, intersect(), Geom::intersects, Geom::BezierCurve::length(), and result.

◆ inverseUnitCircleTransform()

Affine Geom::Ellipse::inverseUnitCircleTransform ( ) const

Compute the transform that maps this ellipse to the unit circle.

This may be a little more precise and/or faster than simply using unitCircleTransform().inverse(). An exception will be thrown for degenerate ellipses.

Definition at line 117 of file ellipse.cpp.

References _angle, center(), ray(), Geom::X, and Geom::Y.

Referenced by contains(), intersect(), Geom::EllipticalArc::inverseUnitCircleTransform(), and timeAt().

◆ majorAxis()

LineSegment Geom::Ellipse::majorAxis ( ) const
inline

Definition at line 163 of file ellipse.h.

References axis(), ray(), Geom::X, and Geom::Y.

Referenced by intersect(), and intersect().

◆ makeCanonical()

void Geom::Ellipse::makeCanonical ( )

Definition at line 342 of file ellipse.cpp.

References _angle, _rays, Geom::X, and Geom::Y.

Referenced by setCoefficients().

◆ minorAxis()

LineSegment Geom::Ellipse::minorAxis ( ) const
inline

Definition at line 164 of file ellipse.h.

References axis(), ray(), Geom::X, and Geom::Y.

◆ operator*=() [1/5]

◆ operator*=() [2/5]

Ellipse & Geom::Ellipse::operator*= ( Rotate const &  r)

Definition at line 284 of file ellipse.cpp.

References _angle, _center, and Geom::Rotate::angle().

◆ operator*=() [3/5]

Ellipse & Geom::Ellipse::operator*= ( Scale const &  s)
inline

Definition at line 220 of file ellipse.h.

References _center, and _rays.

◆ operator*=() [4/5]

Ellipse & Geom::Ellipse::operator*= ( Translate const &  t)
inline

Definition at line 216 of file ellipse.h.

References _center.

◆ operator*=() [5/5]

Ellipse & Geom::Ellipse::operator*= ( Zoom const &  z)
inline

Definition at line 225 of file ellipse.h.

References _center, _rays, and Geom::Zoom::scale().

◆ operator==()

bool Geom::Ellipse::operator== ( Ellipse const &  other) const

Compare ellipses for exact equality.

Definition at line 722 of file ellipse.cpp.

References _angle, _center, _rays, and canonicalForm().

◆ pointAt()

Point Geom::Ellipse::pointAt ( Coord  t) const

Evaluate a point on the ellipse.

The parameter range is \([0, 2\pi)\); larger and smaller values wrap around.

Definition at line 358 of file ellipse.cpp.

References unitCircleTransform().

Referenced by Geom::EllipticalArc::_intersectSameEllipse(), Geom::EllipticalArc::_validateIntersection(), Geom::PathSink::feed(), Geom::Path::Path(), Geom::EllipticalArc::pointAt(), Geom::EllipticalArc::pointAtAngle(), TEST(), TEST(), and TEST().

◆ ray()

◆ rays()

Point Geom::Ellipse::rays ( ) const
inline

Get both rays as a point.

Definition at line 122 of file ellipse.h.

References _rays.

Referenced by operator<<(), Geom::Path::Path(), and Geom::EllipticalArc::rays().

◆ rotationAngle()

◆ semiaxis()

LineSegment Geom::Ellipse::semiaxis ( Dim2  d,
int  sign = 1 
) const

Definition at line 137 of file ellipse.cpp.

References Geom::sgn(), Geom::sign(), Geom::Curve::transform(), and unitCircleTransform().

Referenced by semimajorAxis(), and semiminorAxis().

◆ semimajorAxis()

LineSegment Geom::Ellipse::semimajorAxis ( int  sign = 1) const
inline

Definition at line 165 of file ellipse.h.

References ray(), semiaxis(), Geom::sign(), Geom::X, and Geom::Y.

◆ semiminorAxis()

LineSegment Geom::Ellipse::semiminorAxis ( int  sign = 1) const
inline

Definition at line 168 of file ellipse.h.

References ray(), semiaxis(), Geom::sign(), Geom::X, and Geom::Y.

◆ set() [1/2]

void Geom::Ellipse::set ( Coord  cx,
Coord  cy,
Coord  rx,
Coord  ry,
Coord  a 
)
inline

Set center, rays and angle as constituent values.

Definition at line 97 of file ellipse.h.

References _angle, _center, _rays, Geom::X, and Geom::Y.

◆ set() [2/2]

void Geom::Ellipse::set ( Point const &  c,
Point const &  r,
Coord  angle 
)
inline

Set center, rays and angle.

Definition at line 91 of file ellipse.h.

References _angle, _center, _rays, and c.

Referenced by TEST().

◆ setCenter() [1/2]

void Geom::Ellipse::setCenter ( Coord  cx,
Coord  cy 
)
inline

Set the center by coordinates.

Definition at line 109 of file ellipse.h.

References _center, Geom::X, and Geom::Y.

◆ setCenter() [2/2]

void Geom::Ellipse::setCenter ( Point const &  p)
inline

◆ setCoefficients()

void Geom::Ellipse::setCoefficients ( double  A,
double  B,
double  C,
double  D,
double  E,
double  F 
)

Set an ellipse by solving its implicit equation.

Definition at line 48 of file ellipse.cpp.

References _angle, _center, _rays, D, makeCanonical(), num, Geom::sincos(), Geom::sqr(), Geom::X, and Geom::Y.

Referenced by Ellipse(), Geom::NL::LFMEllipse::instance(), operator*=(), and wrap_ellipse().

◆ setRay()

void Geom::Ellipse::setRay ( Coord  r,
Dim2  d 
)
inline

Set one of the rays of the ellipse.

Definition at line 115 of file ellipse.h.

References _rays.

◆ setRays() [1/2]

void Geom::Ellipse::setRays ( Coord  x,
Coord  y 
)
inline

Set both rays of the ellipse as coordinates.

Definition at line 113 of file ellipse.h.

References _rays, Geom::X, and Geom::Y.

◆ setRays() [2/2]

void Geom::Ellipse::setRays ( Point const &  p)
inline

◆ setRotationAngle()

void Geom::Ellipse::setRotationAngle ( Angle  a)
inline

Set the angle the X ray makes with the +X axis.

Definition at line 117 of file ellipse.h.

References _angle.

Referenced by Geom::EllipticalArc::_updateCenterAndAngles(), are_near(), Geom::EllipticalArc::operator*=(), Geom::EllipticalArc::set(), and Geom::EllipticalArc::set().

◆ timeAt()

Coord Geom::Ellipse::timeAt ( Point const &  p) const

Find the time value of a point on an ellipse.

If the point is not on the ellipse, the returned time value will correspond to an intersection with a ray from the origin passing through the point with the ellipse. Note that this is NOT the nearest point on the ellipse.

Definition at line 382 of file ellipse.cpp.

References Geom::atan2(), axis(), inverseUnitCircleTransform(), Geom::Angle::radians0(), ray(), timeAt(), Geom::X, and Geom::Y.

Referenced by intersect(), Geom::EllipticalArc::operator*=(), TEST(), and timeAt().

◆ unitCircleTransform()

Affine Geom::Ellipse::unitCircleTransform ( ) const

Compute the transform that maps the unit circle to this ellipse.

Each ellipse can be interpreted as a translated, scaled and rotate unit circle. This function returns the transform that maps the unit circle to this ellipse.

Returns
Transform from unit circle to the ellipse

Definition at line 110 of file ellipse.cpp.

References _angle, center(), ray(), Geom::Affine::setTranslation(), Geom::X, and Geom::Y.

Referenced by are_near(), axis(), boundsExact(), Inkscape::LivePathEffect::LPEEllipse5Pts::doEffect_path(), pointAt(), semiaxis(), Geom::EllipticalArc::unitCircleTransform(), and unitTangentAt().

◆ unitTangentAt()

Point Geom::Ellipse::unitTangentAt ( Coord  t) const

Get the value of the derivative at time t normalized to unit length.

Definition at line 398 of file ellipse.cpp.

References Geom::Point::normalize(), unitCircleTransform(), and Geom::Affine::withoutTranslation().

Referenced by TEST().

◆ valueAt()

Coord Geom::Ellipse::valueAt ( Coord  t,
Dim2  d 
) const

Evaluate a single coordinate of a point on the ellipse.

Definition at line 365 of file ellipse.cpp.

References center(), ray(), rotationAngle(), Geom::sincos(), Geom::X, and Geom::Y.

Referenced by Geom::EllipticalArc::valueAtAngle().

Friends And Related Symbol Documentation

◆ are_near()

bool are_near ( Ellipse const &  a,
Ellipse const &  b,
Coord  precision = EPSILON 
)
related

Test whether two ellipses are approximately the same.

This will check whether no point on ellipse a is further away from the corresponding point on ellipse b than precision.

Definition at line 736 of file ellipse.cpp.

References Geom::are_near(), Geom::distance(), Geom::Angle::radians0(), ray(), rotationAngle(), setRays(), setRotationAngle(), unitCircleTransform(), Geom::X, and Geom::Y.

Referenced by operator*=().

◆ operator<<()

std::ostream & operator<< ( std::ostream &  out,
Ellipse const &  e 
)
related

Outputs ellipse data, useful for debugging.

Definition at line 769 of file ellipse.cpp.

References center(), Geom::format_coord_nice(), Geom::operator<<(), rays(), and rotationAngle().

Member Data Documentation

◆ _angle

◆ _center

◆ _rays

Point Geom::Ellipse::_rays
private

The documentation for this class was generated from the following files: