marLine.cpp
Go to the documentation of this file.00001
00002 #include "marLine.h"
00003
00004
00005
00006 marLine::marLine(){
00007 this->a = 1;
00008 this->b = 1;
00009 this->c = 0;
00010 }
00011
00012
00013 marLine::marLine(double x1, double y1, double x2, double y2){
00014 this->a = y2 - y1;
00015 this->b = (x1 - x2);
00016 this->c = (y1 - y2) * x1 + (x2 - x1)*y1;
00017 }
00018
00019
00020 marLine::marLine(double a, double b){
00021 this->a = a;
00022 this->b = b;
00023 this->c = 0;
00024 }
00025
00026
00027 void marLine::getNormal(double *a, double *b){
00028 *a = (this->b);
00029 *b = this->a;
00030 }
00031
00032
00033 void marLine::getIntersect(double a, double b, double c, double *x, double *y){
00034
00035 if (this->a == a){
00036 *x = -1;
00037 *y = -1;
00038 return;
00039 }
00040
00041 if (this->b == b){
00042 *x = -1;
00043 *y = -1;
00044 return;
00045 }
00046
00047 *x = (c*this->b - this->c*b) / (this->a*b - a*this->b);
00048
00049 if (this->b == 0){
00050 *y = -c/b;
00051 } else if (b == 0){
00052 *y = -this->c/this->b;
00053 } else {
00054 *y = (-this->a*(*x) - this->c) / this->b;
00055 }
00056
00057
00058 if (*x < 0 || *y < 0){
00059 *x = -1;
00060 *y = -1;
00061 }
00062
00063 }
00064
00065 double marLine::getA(){
00066 return a;
00067 }
00068
00069
00070 double marLine::getB(){
00071 return b;
00072 }
00073
00074
00075 double marLine::getC(){
00076 return c;
00077 }
00078
00079
00080 marLine::~marLine(){
00081 }
00082