Inkscape
Vector Graphics Editor
|
Set of points with a constant sum of distances from two foci. More...
#include <ellipse.h>
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. | |
EllipticalArc * | arc (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< ShapeIntersection > | intersect (Line const &line) const |
Compute intersections with an infinite line. | |
std::vector< ShapeIntersection > | intersect (LineSegment const &seg) const |
Compute intersections with a line segment. | |
std::vector< ShapeIntersection > | intersect (Ellipse const &other) const |
Compute intersections with another ellipse. | |
std::vector< ShapeIntersection > | intersect (D2< Bezier > const &other) const |
Compute intersections with a 2D Bezier polynomial. | |
Ellipse & | operator*= (Translate const &t) |
Ellipse & | operator*= (Scale const &s) |
Ellipse & | operator*= (Zoom const &z) |
Ellipse & | operator*= (Rotate const &r) |
Ellipse & | operator*= (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. | |
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\)
|
inline |
Definition at line 84 of file ellipse.h.
References D, and setCoefficients().
Geom::Ellipse::Ellipse | ( | Geom::Circle const & | c | ) |
Construct ellipse from a circle.
Definition at line 42 of file ellipse.cpp.
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.
ip | Initial point of the arc |
inner | Point in the middle of the arc, used to pick one of two possibilities |
fp | Final point of the arc |
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().
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().
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().
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().
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==().
|
inline |
Definition at line 119 of file ellipse.h.
References _center.
Referenced by Geom::EllipticalArc::center(), Geom::EllipticalArc::center(), coefficients(), Inkscape::LivePathEffect::LPEPts2Ellipse::genFitEllipse(), Inkscape::LivePathEffect::LPEPts2Ellipse::genPerspectiveEllipse(), initialPoint(), inverseUnitCircleTransform(), operator<<(), TEST(), unitCircleTransform(), valueAt(), and wrap_ellipse().
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*=().
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.
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().
|
inline |
Get the point corresponding to the +X ray of the ellipse.
Definition at line 130 of file ellipse.h.
References initialPoint().
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().
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().
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.
std::vector< ShapeIntersection > Geom::Ellipse::intersect | ( | Ellipse const & | other | ) | const |
Compute intersections with another ellipse.
Discriminant within this radius of 0 will be considered zero.
Definition at line 546 of file ellipse.cpp.
References boundsFast(), bs, c, coefficients(), D, Geom::xAx::decompose_df(), Geom::degen, delta, Geom::double_axis_intersections(), Geom::Intersection< TimeA, TimeB >::first, Geom::infinity(), intersect(), Geom::intersects, K, majorAxis(), Geom::middle_point(), Geom::Intersection< TimeA, TimeB >::point(), ray(), Geom::rescale_homogenous(), result, Geom::solve_cubic(), Geom::sqr(), Geom::X, and Geom::Y.
std::vector< ShapeIntersection > Geom::Ellipse::intersect | ( | Line const & | line | ) | const |
Compute intersections with an infinite line.
Definition at line 460 of file ellipse.cpp.
References Geom::atan2(), c, coefficients(), Geom::Line::coefficients(), D, Geom::double_axis_intersections(), Geom::Line::intersect(), inverseUnitCircleTransform(), Geom::Line::isDegenerate(), K, majorAxis(), ray(), Geom::rescale_homogenous(), result, Geom::solve_quadratic(), Geom::Line::timeAt(), Geom::Line::vector(), Geom::X, and Geom::Y.
Referenced by Geom::EllipticalArc::intersect(), intersect(), intersect(), TEST(), TEST(), and TEST().
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.
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().
|
inline |
Definition at line 163 of file ellipse.h.
References axis(), ray(), Geom::X, and Geom::Y.
Referenced by intersect(), and intersect().
void Geom::Ellipse::makeCanonical | ( | ) |
Definition at line 342 of file ellipse.cpp.
References _angle, _rays, Geom::X, and Geom::Y.
Referenced by setCoefficients().
|
inline |
Definition at line 291 of file ellipse.cpp.
References _angle, _center, _rays, are_near(), Geom::atan2(), coefficients(), Geom::Affine::descrim(), Geom::Affine::inverse(), Geom::Affine::isScale(), Geom::L2(), Geom::Angle::radians(), ray(), setCoefficients(), Geom::Affine::withoutTranslation(), Geom::X, and Geom::Y.
Definition at line 284 of file ellipse.cpp.
References _angle, _center, and Geom::Rotate::angle().
Definition at line 225 of file ellipse.h.
References _center, _rays, and Geom::Zoom::scale().
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().
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().
Get one ray of the ellipse.
Definition at line 124 of file ellipse.h.
References _rays.
Referenced by arc(), are_near(), area_goal(), boundsFast(), coefficients(), Inkscape::LivePathEffect::LPEEllipse5Pts::doEffect_path(), Geom::PathSink::feed(), Inkscape::LivePathEffect::LPEPts2Ellipse::genFitEllipse(), Inkscape::LivePathEffect::LPEPts2Ellipse::genPerspectiveEllipse(), initialPoint(), intersect(), intersect(), inverseUnitCircleTransform(), majorAxis(), minorAxis(), operator*=(), Inkscape::LivePathEffect::path_from_piecewise_fix_cusps(), perimeter_goal(), Geom::EllipticalArc::ray(), semimajorAxis(), semiminorAxis(), timeAt(), unitCircleTransform(), valueAt(), and wrap_ellipse().
|
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().
|
inline |
Get the angle the X ray makes with the +X axis.
Definition at line 126 of file ellipse.h.
References _angle.
Referenced by arc(), are_near(), Geom::PathSink::feed(), Inkscape::LivePathEffect::LPEPts2Ellipse::genFitEllipse(), Inkscape::LivePathEffect::LPEPts2Ellipse::genPerspectiveEllipse(), operator<<(), Geom::Path::Path(), Inkscape::LivePathEffect::path_from_piecewise_fix_cusps(), Geom::EllipticalArc::rotationAngle(), valueAt(), and wrap_ellipse().
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().
|
inline |
Definition at line 165 of file ellipse.h.
References ray(), semiaxis(), Geom::sign(), Geom::X, and Geom::Y.
|
inline |
Definition at line 168 of file ellipse.h.
References ray(), semiaxis(), Geom::sign(), Geom::X, and Geom::Y.
|
inline |
Set the center.
Definition at line 107 of file ellipse.h.
References _center.
Referenced by Geom::EllipticalArc::_updateCenterAndAngles(), Geom::EllipticalArc::derivative(), and Geom::EllipticalArc::operator*=().
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().
|
inline |
Set both rays of the ellipse.
Definition at line 111 of file ellipse.h.
References _rays.
Referenced by Geom::EllipticalArc::_updateCenterAndAngles(), are_near(), Geom::EllipticalArc::operator*=(), Geom::EllipticalArc::set(), and Geom::EllipticalArc::set().
|
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().
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().
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.
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().
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().
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().
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*=().
|
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().
|
private |
Definition at line 71 of file ellipse.h.
Referenced by coefficients(), initialPoint(), inverseUnitCircleTransform(), makeCanonical(), operator*=(), operator*=(), operator==(), rotationAngle(), set(), set(), setCoefficients(), setRotationAngle(), and unitCircleTransform().
|
private |
Definition at line 69 of file ellipse.h.
Referenced by arc(), boundsFast(), center(), center(), operator*=(), operator*=(), operator*=(), operator*=(), operator*=(), operator==(), set(), set(), setCenter(), setCenter(), and setCoefficients().
|
private |
Definition at line 70 of file ellipse.h.
Referenced by makeCanonical(), operator*=(), operator*=(), operator*=(), operator==(), ray(), rays(), set(), set(), setCoefficients(), setRay(), setRays(), and setRays().