]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/kernel/marLine.cpp
BUG macOs
[creaMaracasVisu.git] / lib / maracasVisuLib / src / kernel / marLine.cpp
1
2 #include "marLine.h"
3
4 // ----------------------------------------------------------------------------
5 // ----------------------------------------------------------------------------
6 marLine::marLine(){
7         this->a = 1;
8         this->b = 1;
9         this->c = 0;
10 }
11
12 // ----------------------------------------------------------------------------
13 marLine::marLine(double x1, double y1, double x2, double y2){
14         this->a = y2 - y1;                      //REVISAR SIGNO
15         this->b = (x1 - x2);
16         this->c = (y1 - y2) * x1 + (x2 - x1)*y1;
17 }
18
19 // ----------------------------------------------------------------------------
20 marLine::marLine(double a, double b){
21         this->a = a;
22         this->b = b;
23         this->c = 0;
24 }
25
26 // ----------------------------------------------------------------------------
27 void marLine::getNormal(double *a, double *b){
28         *a = (this->b);
29         *b = this->a;
30 }
31
32 // ----------------------------------------------------------------------------
33 void marLine::getIntersect(double a, double b, double c, double *x, double *y){
34
35         if (this->a == a){
36                 *x = -1;
37                 *y = -1;
38                 return;
39         }
40
41         if (this->b == b){
42                 *x = -1;
43                 *y = -1;
44                 return;
45         }
46
47         *x = (c*this->b - this->c*b) / (this->a*b - a*this->b);
48
49         if (this->b == 0){
50                 *y = -c/b;
51         } else if (b == 0){
52                 *y = -this->c/this->b;
53         } else {
54                 *y = (-this->a*(*x) - this->c) / this->b;
55         }
56         
57
58         if (*x < 0 || *y < 0){
59                 *x = -1;
60                 *y = -1;
61         }
62         
63 }
64 // ----------------------------------------------------------------------------
65 double marLine::getA(){
66         return a;
67 }
68
69 // ----------------------------------------------------------------------------
70 double marLine::getB(){
71         return b;
72 }
73
74 // ----------------------------------------------------------------------------
75 double marLine::getC(){
76         return c;
77 }
78
79 // ----------------------------------------------------------------------------
80 marLine::~marLine(){
81 }
82