moved kdeaccessibility kdeaddons kdeadmin kdeartwork kdebindings kdeedu kdegames...
[kdeedu.git] / kig / misc / cubic-common.h
blobf989bfa98447c85324afab62418e903f8aa7db66
1 // Copyright (C) 2003 Dominique Devriese <devriese@kde.org>
3 // This program is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU General Public License
5 // as published by the Free Software Foundation; either version 2
6 // of the License, or (at your option) any later version.
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
16 // 02111-1307, USA.
18 #ifndef KIG_MISC_CUBIC_COMMON_H
19 #define KIG_MISC_CUBIC_COMMON_H
21 #include "common.h"
23 class Transformation;
25 /**
26 * This class represents an equation of a cubic in the form
27 * "a_{ijk} x_i x_j x_k = 0" (in homogeneous coordinates, i,j,k = 0,1,2),
28 * i <= j <= k.
29 * The coefficients are stored in lessicografic order.
31 class CubicCartesianData
33 public:
34 double coeffs[10];
35 explicit CubicCartesianData();
36 CubicCartesianData( double a000, double a001, double a002,
37 double a011, double a012, double a022,
38 double a111, double a112, double a122,
39 double a222 )
41 coeffs[0] = a000;
42 coeffs[1] = a001;
43 coeffs[2] = a002;
44 coeffs[3] = a011;
45 coeffs[4] = a012;
46 coeffs[5] = a022;
47 coeffs[6] = a111;
48 coeffs[7] = a112;
49 coeffs[8] = a122;
50 coeffs[9] = a222;
52 CubicCartesianData( const double incoeffs[10] );
54 static CubicCartesianData invalidData();
55 bool valid() const;
58 bool operator==( const CubicCartesianData& lhs, const CubicCartesianData& rhs );
60 /**
61 * This function calcs a cartesian cubic equation such that the
62 * given points are on the cubic. There can be at most 9 and at
63 * least 2 point. If there are less than 9, than the coefficients
64 * will be chosen to 1.0 if possible
67 const CubicCartesianData calcCubicThroughPoints (
68 const std::vector<Coordinate>& points );
70 const CubicCartesianData calcCubicCuspThroughPoints (
71 const std::vector<Coordinate>& points );
73 const CubicCartesianData calcCubicNodeThroughPoints (
74 const std::vector<Coordinate>& points );
76 double calcCubicYvalue ( double x, double ymin, double ymax,
77 int root, CubicCartesianData data,
78 bool& valid, int& numroots );
80 const Coordinate calcCubicLineIntersect( const CubicCartesianData& c,
81 const LineData& l,
82 int root, bool& valid );
84 void calcCubicLineRestriction ( CubicCartesianData data,
85 Coordinate p1, Coordinate dir,
86 double& a, double& b, double& c, double& d );
88 const CubicCartesianData calcCubicTransformation (
89 const CubicCartesianData& data,
90 const Transformation& t, bool& valid );
92 #endif