1 /**
2 * \file
3 * \brief Ellipse Curve
4 *
5 * Authors:
6 * Marco Cecchetti <mrcekets at gmail.com>
7 *
8 * Copyright 2008 authors
9 *
10 * This library is free software; you can redistribute it and/or
11 * modify it either under the terms of the GNU Lesser General Public
12 * License version 2.1 as published by the Free Software Foundation
13 * (the "LGPL") or, at your option, under the terms of the Mozilla
14 * Public License Version 1.1 (the "MPL"). If you do not alter this
15 * notice, a recipient may use your version of this file under either
16 * the MPL or the LGPL.
17 *
18 * You should have received a copy of the LGPL along with this library
19 * in the file COPYING-LGPL-2.1; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 * You should have received a copy of the MPL along with this library
22 * in the file COPYING-MPL-1.1
23 *
24 * The contents of this file are subject to the Mozilla Public License
25 * Version 1.1 (the "License"); you may not use this file except in
26 * compliance with the License. You may obtain a copy of the License at
27 * http://www.mozilla.org/MPL/
28 *
29 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
30 * OF ANY KIND, either express or implied. See the LGPL or the MPL for
31 * the specific language governing rights and limitations.
32 */
35 #ifndef _2GEOM_ELLIPSE_H_
36 #define _2GEOM_ELLIPSE_H_
39 #include <2geom/point.h>
40 #include <2geom/exception.h>
41 #include <2geom/matrix.h>
43 namespace Geom
44 {
46 class SVGEllipticalArc;
47 class Circle;
49 class Ellipse
50 {
51 public:
52 Ellipse()
53 {}
55 Ellipse(double cx, double cy, double rx, double ry, double a)
56 : m_centre(cx, cy), m_ray(rx, ry), m_angle(a)
57 {
58 }
60 // build an ellipse by its implicit equation:
61 // Ax^2 + Bxy + Cy^2 + Dx + Ey + F = 0
62 Ellipse(double A, double B, double C, double D, double E, double F)
63 {
64 set(A, B, C, D, E, F);
65 }
67 Ellipse(std::vector<Point> const& points)
68 {
69 set(points);
70 }
72 Ellipse(Geom::Circle const &c);
74 void set(double cx, double cy, double rx, double ry, double a)
75 {
76 m_centre[X] = cx;
77 m_centre[Y] = cy;
78 m_ray[X] = rx;
79 m_ray[Y] = ry;
80 m_angle = a;
81 }
83 // build an ellipse by its implicit equation:
84 // Ax^2 + Bxy + Cy^2 + Dx + Ey + F = 0
85 void set(double A, double B, double C, double D, double E, double F);
87 // biuld up the best fitting ellipse wrt the passed points
88 // prerequisite: at least 5 points must be passed
89 void set(std::vector<Point> const& points);
91 SVGEllipticalArc
92 arc(Point const& initial, Point const& inner, Point const& final,
93 bool _svg_compliant = true);
95 Point center() const
96 {
97 return m_centre;
98 }
100 Coord center(Dim2 d) const
101 {
102 return m_centre[d];
103 }
105 Coord ray(Dim2 d) const
106 {
107 return m_ray[d];
108 }
110 Coord rot_angle() const
111 {
112 return m_angle;
113 }
115 std::vector<double> implicit_form_coefficients() const;
117 Ellipse transformed(Matrix const& m) const;
119 private:
120 Point m_centre, m_ray;
121 double m_angle;
122 };
125 } // end namespace Geom
129 #endif // _2GEOM_ELLIPSE_H_
132 /*
133 Local Variables:
134 mode:c++
135 c-file-style:"stroustrup"
136 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
137 indent-tabs-mode:nil
138 fill-column:99
139 End:
140 */
141 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :