moved kdeaccessibility kdeaddons kdeadmin kdeartwork kdebindings kdeedu kdegames...
[kdeedu.git] / kig / misc / conic-common.h
blob8a3522b370c98897d49acca9c1eb951a401f3093
1 /**
2 This file is part of Kig, a KDE program for Interactive Geometry...
3 Copyright (C) 2002 Maurizio Paolini <paolini@dmf.unicatt.it>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18 USA
19 **/
21 #ifndef KIG_MISC_CONIC_COMMON_H
22 #define KIG_MISC_CONIC_COMMON_H
24 #include "coordinate.h"
25 #include <vector>
26 #include "kignumerics.h"
28 class ConicPolarData;
29 class Transformation;
30 class LineData;
32 /**
33 * Cartesian Conic Data. This class represents an equation of a conic
34 * in the form "ax^2 + by^2 + cxy + dx + ey + f = 0".
35 * \internal The coefficients are stored in the order a - f.
37 class ConicCartesianData
39 public:
40 double coeffs[6];
41 ConicCartesianData();
42 /**
43 * Construct a ConicCartesianData from a ConicPolarData.
44 * Construct a ConicCartesianData that is the cartesian
45 * representation of the conic represented by d.
47 explicit ConicCartesianData( const ConicPolarData& d );
48 /**
49 * Construct a ConicCartesianData from its coefficients
50 * Construct a ConicCartesianData using the coefficients a through f
51 * from the equation "ax^2 + by^2 + cxy + dx + ey + f = 0"
53 ConicCartesianData( double a, double b, double c,
54 double d, double e, double f )
56 coeffs[0] = a;
57 coeffs[1] = b;
58 coeffs[2] = c;
59 coeffs[3] = d;
60 coeffs[4] = e;
61 coeffs[5] = f;
63 ConicCartesianData( const double incoeffs[6] );
65 /**
66 * Invalid conic.
67 * Return a ConicCartesianData representing an invalid conic.
68 * \see valid()
70 static ConicCartesianData invalidData();
71 /**
72 * Test validity.
73 * Return whether this is a valid conic.
74 * \see invalidData()
76 bool valid() const;
79 /**
80 * This class represents an equation of a conic in the form
81 * "\rho(\theta) = \frac{p}{1 - e \cos\theta}" ( run this through
82 * LaTeX to get nice output ;) focus and the ecostheta stuff
83 * represent the coordinate system in which the equation yields the
84 * good result..
86 class ConicPolarData
88 public:
89 /**
90 * Construct a ConicPolarData from a ConicCartesianData.
92 * Construct a ConicPolarData that is the polar
93 * representation of the conic represented by d.
95 explicit ConicPolarData( const ConicCartesianData& data );
96 explicit ConicPolarData();
97 /**
98 * Construct a ConicPolarData using the parameters from the equation
99 * "\rho(\theta) = \frac{p}{1 - e \cos\theta}"
101 ConicPolarData( const Coordinate& focus1, double dimen,
102 double ecostheta0, double esintheta0 );
105 * The first focus of this conic.
107 Coordinate focus1;
109 * The pdimen value from the polar equation.
111 double pdimen;
113 * The ecostheta0 value from the polar equation.
115 double ecostheta0;
117 * The esintheta0 value from the polar equation.
119 double esintheta0;
122 bool operator==( const ConicPolarData& lhs, const ConicPolarData& rhs );
125 * These are the constraint values that can be passed to the
126 * calcConicThroughPoints function. Their meaning is as follows:
127 * noconstraint: no additional points will be calculated.
128 * zerotilt: force the symmetry axes to be parallel to the coordinate
129 * system ( zero tilt ).
130 * parabolaifzt: the returned conic should be a parabola ( if used in
131 * combination with zerotilt )
132 * circleifzt: the returned conic should be a circle ( if used in
133 * combination with zerotilt )
134 * equilateral: the returned conic should be equilateral
135 * ysymmetry: the returned conic should be symmetric over the Y-axis.
136 * xsymmetry: the returned conic should be symmetric over the X-axis.
138 enum LinearConstraints {
139 noconstraint, zerotilt, parabolaifzt, circleifzt,
140 equilateral, ysymmetry, xsymmetry
144 * Calculate a conic through a given set of points. points should
145 * contain at least one, and at most five points. If there are five
146 * points, then the conic is completely defined. If there are less,
147 * then additional points will be calculated according to the
148 * constraints given. See above for the various constraints.
150 * An invalid ConicCartesianData is returned if there is no conic
151 * through the given set of points, or if not enough constraints are
152 * given for a conic to be calculated.
154 const ConicCartesianData calcConicThroughPoints (
155 const std::vector<Coordinate>& points,
156 const LinearConstraints c1 = noconstraint,
157 const LinearConstraints c2 = noconstraint,
158 const LinearConstraints c3 = noconstraint,
159 const LinearConstraints c4 = noconstraint,
160 const LinearConstraints c5 = noconstraint);
163 * This function is used by ConicBFFP. It calcs the polar equation
164 * for a hyperbola ( type == -1 ) or ellipse ( type == 1 ) with
165 * focuses args[0] and args[1], and with args[2] on the edge of the
166 * conic. args.size() should be two or three. If it is two, the two
167 * points are taken to be the focuses, and a third point is chosen in
168 * a sensible way..
170 const ConicPolarData calcConicBFFP(
171 const std::vector<Coordinate>& args,
172 int type );
175 * function used by ConicBDFP. It calcs the conic with directrix d,
176 * focus f, and point p on the conic..
178 const ConicPolarData calcConicBDFP(
179 const LineData& d, const Coordinate& f, const Coordinate& p );
182 * This calcs the hyperbola defined by its two asymptotes line1 and
183 * line2, and a point p on the edge.
185 const ConicCartesianData calcConicByAsymptotes(
186 const LineData& line1,
187 const LineData& line2,
188 const Coordinate& p );
191 * This function calculates the polar line of the point cpole with
192 * respect to the given conic data. As the last argument, you should
193 * pass a reference to a boolean. This boolean will be set to true if
194 * the returned LineData is valid, and to false if the returned line
195 * is not valid. The latter condition only occurs if a "line at
196 * infinity" would have had to be returned.
198 const LineData calcConicPolarLine (
199 const ConicCartesianData& data,
200 const Coordinate& cpole,
201 bool& valid );
204 * This function calculates the polar point of the line polar with
205 * respect to the given conic data. As the last argument, you should
206 * pass a reference to a boolean. This boolean will be set to true if
207 * the returned LineData is valid, and to false if the returned line
208 * is not valid. The latter condition only occurs if a "point at
209 * infinity" would have had to be returned.
211 const Coordinate calcConicPolarPoint (
212 const ConicCartesianData& data,
213 const LineData& polar );
216 * This function calculates the intersection of a given line ( l ) and
217 * a given conic ( c ). A line and a conic have two intersections in
218 * general, and as such, which should be set to -1 or 1 depending on
219 * which intersection you want. As the last argument, you should pass
220 * a reference to a boolean. This boolean will be set to true if the
221 * returned point is valid, and to false if the returned point is not
222 * valid. The latter condition only occurs if the given conic and
223 * line do not have the specified intersection.
225 * knownparam is something special: If you already know one
226 * intersection of the line and the conic, and you want the other one,
227 * then you should set which to 0, knownparam to the curve parameter
228 * of the point you already know ( i.e. the value returned by
229 * conicimp->getParam( otherpoint ) ).
231 const Coordinate calcConicLineIntersect( const ConicCartesianData& c,
232 const LineData& l,
233 double knownparam,
234 int which );
237 * This function calculates the asymptote of the given conic ( data ).
238 * A conic has two asymptotes in general, so which should be set to +1
239 * or -1 depending on which asymptote you want. As the last argument,
240 * you should pass a reference to a boolean. This boolean will be set
241 * to true if the returned line is valid, and to false if the returned
242 * line is not valid. The latter condition only occurs if the given
243 * conic does not have the specified asymptote.
245 const LineData calcConicAsymptote(
246 const ConicCartesianData data,
247 int which, bool &valid );
250 * This function calculates the radical line of two conics. A radical
251 * line is the line that goes through two of the intersections of two
252 * conics. Since two conics have up to four intersections in general,
253 * there are three sets of two radical lines. zeroindex specifies
254 * which set of radical lines you want ( set it to 1, 2 or 3 ), and
255 * which is set to -1 or +1 depending on which of the two radical
256 * lines in the set you want. As the last argument, you should pass a
257 * reference to a boolean. This boolean will be set to true if the
258 * returned line is valid, and to false if the returned line is not
259 * valid. The latter condition only occurs if the given conics do not
260 * have the specified radical line.
262 const LineData calcConicRadical( const ConicCartesianData& cequation1,
263 const ConicCartesianData& cequation2,
264 int which, int zeroindex, bool& valid );
267 * This calculates the image of the given conic ( data ) through the
268 * given transformation ( t ). As the last argument, you should pass
269 * a reference to a boolean. This boolean will be set to true if the
270 * returned line is valid, and to false if the returned line is not
271 * valid. The latter condition only occurs if the given
272 * transformation is singular, and as such, the transformation of the
273 * conic cannot be calculated.
275 const ConicCartesianData calcConicTransformation (
276 const ConicCartesianData& data,
277 const Transformation& t, bool& valid );
279 #endif // KIG_MISC_CONIC_COMMON_H