LibreCAD
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
equation.cpp
Go to the documentation of this file.
1 //
2 // Created by gagan on 5/14/16.
3 //
4 
5 #include "equation.h"
6 
7 using namespace lc;
8 using namespace maths;
9 
10 Equation::Equation() : matrix_(Eigen::Matrix3d::Zero()) {
11 
12 }
13 
14 Equation::Equation(Eigen::Matrix3d &mat) : matrix_(mat) {
15 
16 }
17 
19  matrix_ = qm.Matrix();
20  return *this;
21 }
22 
23 Equation::Equation(double a, double b, double c, double d,
24  double e, double f) :
25  matrix_((Eigen::Matrix3d() <<
26  a, b*.5, d*.5,
27  b*.5, c, e*.5,
28  d*.5, e*.5, f
29  ).finished()) {
30 }
31 
32 Equation::Equation(const std::vector<double>& vec) :
33  matrix_((Eigen::Matrix3d() <<
34  vec[0], vec[1]*.5, vec[3]*.5,
35  vec[1]*.5, vec[2], vec[4]*.5,
36  vec[3]*.5, vec[4]*.5, vec[5]
37  ).finished()) {
38 }
39 
40 const std::vector<double> Equation::Coefficients() const {
41  std::vector<double> vec {{
42  matrix_(0,0), matrix_(0,1) + matrix_(1,0),
43  matrix_(1,1), matrix_(0,2) + matrix_(2,0),
44  matrix_(2,1) + matrix_(1,2), matrix_(2,2) }};
45  return vec;
46 }
47 
49  const geo::Coordinate &v) const {
50  Eigen::Matrix3d mat = translateMatrix(v).transpose() * matrix_ * translateMatrix(v);
51  return Equation(mat);
52 }
53 
54 const Equation Equation::rotate(double angle) const {
55  const auto & m = rotationMatrix(angle);
56  const auto & t = m.transpose();
57  Eigen::Matrix3d ret = t * matrix_ * m;
58  return Equation(ret);
59 }
60 
62  const geo::Coordinate &center, double angle) const {
63  return move(geo::Coordinate(-center.x(), -center.y()))
64  .rotate(angle)
65  .move(center);
66 }
67 
68 Eigen::Matrix3d Equation::rotationMatrix(double angle) {
69  Eigen::Matrix3d mat;
70  mat << std::cos(angle) , std::sin(angle) , 0,
71  -std::sin(angle) , std::cos(angle) , 0,
72  0 , 0 , 1;
73  return mat;
74 }
75 
76 const Eigen::Matrix3d Equation::Matrix() const {
77  return matrix_;
78 }
79 
80 Eigen::Matrix3d Equation::translateMatrix(const geo::Coordinate &v) {
81  Eigen::Matrix3d mat;
82  mat << 1 , 0 , -v.x(),
83  0 , 1 , -v.y(),
84  0 , 0 , 1;
85  return mat;
86 }
87 
88 const Equation Equation::flipXY() const {
89  Eigen::Matrix3d ret;
90 
91  /*
92  * swap a with c
93  * swap d with e
94  * no swaps for consant i.e f
95  */
96 
97  auto lin1 = (matrix_(2,0) + matrix_(0,2)) / 2;
98  auto lin2 = (matrix_(2,1) + matrix_(1,2)) / 2;
99 
100  ret << matrix_(1,1), matrix_(1,0), lin2,
101  matrix_(0,1), matrix_(0,0), lin1,
102  lin2 , lin1 , matrix_(2,2);
103 
104  return ret;
105 }
106 
Equation & operator=(const Equation qm)
Definition: equation.cpp:18
const Eigen::Matrix3d Matrix() const
Matrix Returns matrix of equation.
Definition: equation.cpp:76
double x() const
Returns x of Coordinate.
Definition: geocoordinate.h:26
Eigen::Matrix3d matrix_
Definition: equation.h:95
const std::vector< double > Coefficients() const
Coefficients of the equation.
Definition: equation.cpp:40
double y() const
Returns y of Coordinate.
Definition: geocoordinate.h:34
const Equation flipXY() const
flipXY Flips the matrix values
Definition: equation.cpp:88
Definition: cadentity.h:12
static Eigen::Matrix3d translateMatrix(const geo::Coordinate &v)
translateMatrix Translates the matrix by some coordinate value
Definition: equation.cpp:80
const Equation move(const geo::Coordinate &v) const
move the quadratic equation by value V
Definition: equation.cpp:48
static Eigen::Matrix3d rotationMatrix(double angle)
rotationMatrix Rotates the matrix by an angle
Definition: equation.cpp:68
const Equation rotate(double angle) const
rotate the quadratic equation by value V
Definition: equation.cpp:54