/** @file
* @brief Ellipse shape
*//*
* Authors:
* Marco Cecchetti <mrcekets at gmail.com>
* Krzysztof KosiĆski <tweenk.pl@gmail.com>
*
* Copyright 2008 authors
*
* modify it either under the terms of the GNU Lesser General Public
* License version 2.1 as published by the Free Software Foundation
* (the "LGPL") or, at your option, under the terms of the Mozilla
* Public License Version 1.1 (the "MPL"). If you do not alter this
* notice, a recipient may use your version of this file under either
* the MPL or the LGPL.
*
* You should have received a copy of the LGPL along with this library
* in the file COPYING-LGPL-2.1; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* You should have received a copy of the MPL along with this library
* in the file COPYING-MPL-1.1
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
* OF ANY KIND, either express or implied. See the LGPL or the MPL for
* the specific language governing rights and limitations.
*/
#ifndef LIB2GEOM_SEEN_ELLIPSE_H
#define LIB2GEOM_SEEN_ELLIPSE_H
#include <vector>
/** @brief 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:
* \f$Ax^2 + Bxy + Cy^2 + Dx + Ey + F = 0\f$
*
* @ingroup Shapes */
> > > > > >
{
Ellipse() {}
: _center(c)
, _rays(r)
{}
{}
Ellipse(double A, double B, double C, double D, double E, double F) {
setCoefficients(A, B, C, D, E, F);
}
/// Construct ellipse from a circle.
/// Set center, rays and angle.
_center = c;
_rays = r;
}
/// Set center, rays and angle as constituent values.
_angle = a;
}
/// Set an ellipse by solving its implicit equation.
void setCoefficients(double A, double B, double C, double D, double E, double F);
/// Set the center.
/// Set the center by coordinates.
/// Set both rays of the ellipse.
/// Set both rays of the ellipse as coordinates.
/// Set one of the rays of the ellipse.
/// Set the angle the X ray makes with the +X axis.
/// Get both rays as a point.
/// Get one ray of the ellipse.
/// Get the angle the X ray makes with the +X axis.
/// Get the point corresponding to the +X ray of the ellipse.
Point initialPoint() const;
/// Get the point corresponding to the +X ray of the ellipse.
/** @brief Create an ellipse passing through the specified points
* At least five points have to be specified. */
/** @brief 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.
* @param ip Initial point of the arc
* @param inner Point in the middle of the arc, used to pick one of two possibilities
* @param fp Final point of the arc
* @return Newly allocated arc, delete when no longer used */
/** @brief Return an ellipse with less degrees of freedom.
* The canonical form always has the angle less than \f$\frac{\pi}{2}\f$,
* and zero if the rays are equal (i.e. the ellipse is a circle). */
Ellipse canonicalForm() const;
void makeCanonical();
/** @brief 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.
* @return Transform from unit circle to the ellipse */
Affine unitCircleTransform() const;
/** @brief Compute the transform that maps this ellipse to the unit circle.
* unitCircleTransform().inverse(). An exception will be thrown for
* degenerate ellipses. */
Affine inverseUnitCircleTransform() const;
}
}
/// Get the tight-fitting bounding box of the ellipse.
Rect boundsExact() const;
/// Get the coefficients of the ellipse's implicit equation.
/** @brief Evaluate a point on the ellipse.
* The parameter range is \f$[0, 2\pi)\f$; larger and smaller values
* wrap around. */
/// Evaluate a single coordinate of a point on the ellipse.
/** @brief 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. */
/// Get the value of the derivative at time t normalized to unit length.
/// Check whether the ellipse contains the given point.
/// Compute intersections with an infinite line.
/// Compute intersections with a line segment.
/// Compute intersections with another ellipse.
/// Compute intersections with a 2D Bezier polynomial.
_center *= t;
return *this;
}
_center *= s;
_rays *= s;
return *this;
}
_center *= z;
return *this;
}
/// Compare ellipses for exact equality.
};
/** @brief 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.
* @relates Ellipse */
/** @brief Outputs ellipse data, useful for debugging.
* @relates Ellipse */
} // end namespace Geom
#endif // LIB2GEOM_SEEN_ELLIPSE_H
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :