conicsec.h revision 76addc201c409e81eaaa73fe27cc0f79c4db097c
/** @file
* @brief Conic Section
*//*
* Authors:
* Nathan Hurst <njh@njhurst.com>
*
* Copyright 2009 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_CONICSEC_H
#define LIB2GEOM_SEEN_CONICSEC_H
#include <string>
#include <vector>
#include <ostream>
{
/**
* A curve of the form B02*A + B12*B*w + B22*C/(B02 + B12*w + B22)
* These curves can exactly represent a piece conic section less than a certain angle (find out)
*
**/
Point P[3];
double w;
RatQuad() {}
P[0] = a;
P[1] = b;
P[2] = c;
}
double lambda() const;
Point P,
CubicBezier toCubic() const;
};
double c[6];
enum kind_t
{
TWO_IMAGINARY_CROSSING_LINES, // crossing at a real point
};
xAx() {}
/*
* Define the conic section by its algebraic equation coefficients
*
* c0, .., c5: equation coefficients
*/
{
}
/*
* Define a conic section by its related symmetric matrix
*/
{
set(C);
}
/*
* Define a conic section by computing the one that fits better with
* N points.
*
* points: points to fit
*
* precondition: there must be at least 5 non-overlapping points
*/
{
}
/*
* Define a section conic by providing the coordinates of one of its
* vertex,the major axis inclination angle and the coordinates of its foci
* with respect to the unidimensional system defined by the major axis with
* origin set at the provided vertex.
*
* _vertex : section conic vertex V
* _angle : section conic major axis angle
* _dist1: +/-distance btw V and nearest focus
* _dist2: +/-distance btw V and farest focus
*
* prerequisite: _dist1 <= _dist2
*/
{
}
/*
* Define a conic section by providing one of its vertex and its foci.
*
* _vertex: section conic vertex
* _focus1: section conic focus
* _focus2: section conic focus
*/
{
}
/*
* Define a conic section by passing a focus, the related directrix,
* and the eccentricity (e)
* (e < 1 -> ellipse; e = 1 -> parabola; e > 1 -> hyperbola)
*
* _focus: a focus of the conic section
* _directrix: the directrix related to the given focus
* _eccentricity: the eccentricity parameter of the conic section
*/
{
}
/*
* Made up a degenerate conic section as a pair of lines
*
* l1, l2: lines that made up the conic section
*/
{
}
/*
* Define the conic section by its algebraic equation coefficients
* c0, ..., c5: equation coefficients
*/
{
}
/*
* Define a conic section by its related symmetric matrix
*/
{
}
T evaluate_at(T x, T y) const {
return c[0]*x*x + c[1]*x*y + c[2]*y*y + c[3]*x + c[4]*y + c[5];
}
}
T evaluate_at(T x, T y, T w) const {
return c[0]*x*x + c[1]*x*y + c[2]*y*y + c[3]*x*w + c[4]*y*w + c[5]*w*w;
}
/*
* Return the symmetric matrix related to the conic section.
* Modifying the matrix does not modify the conic section
*/
{
C(1,0) *= 0.5; C(2,0) *= 0.5; C(2,1) *= 0.5;
return C;
}
/*
* Return the i-th coefficient of the conic section algebraic equation
* Modifying the returned value does not modify the conic section coefficient
*/
{
return c[i];
}
/*
* Return the i-th coefficient of the conic section algebraic equation
* Modifying the returned value modifies the conic section coefficient
*/
{
return c[i];
}
/*
* Return true if the equation:
* c0*x^2 + c1*xy + c2*y^2 + c3*x + c4*y +c5 == 0
* really defines a conic, false otherwise
*/
bool is_quadratic() const
{
}
/*
* Return true if the conic is degenerate, i.e. if the related matrix
* determinant is null, false otherwise
*/
bool isDegenerate() const
{
return (det_sgn (get_matrix()) == 0);
}
/*
* Compute the centre of simmetry of the conic section when it exists,
* else it return an unitialized boost::optional<Point> instance.
*/
{
if (are_near (d, 0)) return opt_point_t();
Q(0,0) = coeff(0);
Point C;
C[0] = sol[0];
return opt_point_t(C);
}
double axis_angle() const;
/*
* Rotate the conic section by the given angle wrt the provided point.
*
* _rot_centre: the rotation centre
* _angle: the rotation angle
*/
{
return result;
}
/*
* Compute the tangent line of the conic section at the provided point
*
* _point: the conic section point the tangent line pass through
*/
{
}
/*
* For a non degenerate conic compute the dual conic.
* TODO: investigate degenerate case
*/
{
//assert (! isDegenerate());
return dc;
}
/*
* Generate a RatQuad object from a conic arc.
*
* p0: the initial point of the arc
* p1: the inner point of the arc
* p2: the final point of the arc
*/
{
return
}
/*
* Return the angle related to the normal gradient computed at the passed
* point.
*
* _point: the point at which computes the angle
*
* prerequisite: the passed point must lie on the conic
*/
{
return angle;
}
/*
* Return true if the given point is contained in the conic arc determined
* by the passed points.
*
* _point: the point to be tested
* _initial: the initial point of the arc
* _inner: an inner point of the arc
* _final: the final point of the arc
*
* prerequisite: the passed points must lie on the conic, the inner point
* has to be strictly contained in the arc, except when the
* initial and final points are equal: in such a case if the
* inner point is also equal to them, then they define an arc
* made up by a single point.
*
*/
{
// we test if _point and _inner have the same position
// wrt _initial and _final
}
/*
* Return the point on the conic section nearest to the passed point "P".
*
* P: the point to compute the nearest one
*/
{
{
}
// else
THROW_LOGICALERROR ("nearestTime: no nearest point found");
return Point();
}
};
for(int i = 0; i < 6; i++) {
out_file << x.c[i] << ", ";
}
return out_file;
}
};
#endif // LIB2GEOM_SEEN_CONICSEC_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 :