line2d.cpp
Go to the documentation of this file.
1 #include "tuw_geometry/line2d.h"
2 #include "iostream"
3 
4 using namespace tuw;
6 };
7 Line2D::Line2D ( const Line2D &l ) : cv::Vec<double,3> ( l ) {
8 };
9 Line2D::Line2D ( cv::Vec<double,3> &l, bool normalize )
10  : cv::Vec<double,3> ( l ) {
11  if ( normalize ) this->normalize();
12 };
13 Line2D::Line2D ( const double &x0, const double &y0, const double &x1, const double &y1, bool normalize ) {
14  set ( x0,y0,x1,y1, normalize );
15 }
16 Line2D::Line2D ( const Point2D &p0, const Point2D &p1, bool normalize ) {
17  set ( p0, p1, normalize );
18 }
19 double &Line2D::a() {
20  return this->val[0];
21 }
22 const double &Line2D::a() const {
23  return this->val[0];
24 }
25 double &Line2D::b() {
26  return this->val[1];
27 }
28 const double &Line2D::b() const {
29  return this->val[1];
30 }
31 double &Line2D::c() {
32  return this->val[2];
33 }
34 const double &Line2D::c() const {
35  return this->val[2];
36 }
38  double r = sqrt ( this->val[0]*this->val[0] + this->val[1]*this->val[1] );
39  this->val[0] /= r, this->val[1] /= r, this->val[2] /= r;
40 }
41 double Line2D::distanceTo ( const double &x, const double &y ) const {
42  return this->val[0]*x + this->val[1]*y + this->val[2];
43 }
45 double Line2D::distanceTo ( const Point2D &p ) const {
46  return distanceTo ( p.x(), p.y() );
47 }
49 Point2D Line2D::pointOnLine ( const double &x, const double &y ) const {
50  double d = distanceTo ( x,y );
51  return Point2D ( x - d * a(), y - d * b() );
52 }
55  return pointOnLine ( p.x(), p.y() );
56 }
57 Point2D Line2D::intersection ( const Line2D &l ) const {
58  cv::Vec<double,3> h = this->cross ( l );
59  return Point2D ( h[0]/h[2],h[1]/h[2] );
60 }
61 cv::Vec<double,2> Line2D::normal() const {
62  return cv::Vec<double,2> ( this->val[0], this->val[1] );
63 }
64 Line2D &Line2D::set ( const double &x0, const double &y0, const double &x1, const double &y1, bool normalize ) {
65  this->val[0] = y0-y1, this->val[1] = x1-x0, this->val[2] = x0*y1-y0*x1;
66  if ( normalize ) this->normalize();
67  return *this;
68 }
69 Line2D &Line2D::set ( const Point2D &p0, const Point2D &p1, bool normalize ) {
70  return set ( p0.x(), p0.y(), p1.x(), p1.y(), normalize );
71 }
72 cv::Vec<double,3> &Line2D::cv () {
73  return *this;
74 }
75 const cv::Vec<double,3> &Line2D::cv () const {
76  return *this;
77 }
79 
80  Point2D p ( - c() * a(), - c() * b() ); // nearest point to origin
81  return Polar2D(p.angle(), fabs(c()));
82 }
d
const double & y() const
Definition: point2d.cpp:49
Point2D pointOnLine(const double &x, const double &y) const
Definition: line2d.cpp:49
Line2D()
constructor
Definition: line2d.cpp:5
Point2D intersection(const Line2D &l) const
Definition: line2d.cpp:57
Definition: point2d.h:208
Polar2D toPolar() const
Definition: line2d.cpp:78
cv::Vec< double, 2 > normal() const
Definition: line2d.cpp:61
Line2D & set(const double &x0, const double &y0, const double &x1, const double &y1, bool normalize=true)
Definition: line2d.cpp:64
cv::Vec< double, 3 > & cv()
Definition: line2d.cpp:72
Definition: command.h:8
double angle() const
Definition: point2d.cpp:151
double distanceTo(const double &x, const double &y) const
Definition: line2d.cpp:41
double & c()
Definition: line2d.cpp:31
double & b()
Definition: line2d.cpp:25
const double & x() const
Definition: point2d.cpp:35
double & a()
Definition: line2d.cpp:19
void normalize()
Definition: line2d.cpp:37


tuw_geometry
Author(s): Markus Bader
autogenerated on Mon Jun 10 2019 15:33:08