point2d.cpp
Go to the documentation of this file.
1 #include "tuw_geometry/point2d.h"
2 #include "tuw_geometry/polar2d.h"
3 using namespace tuw;
4 
5 Point2D::Point2D() : cv::Vec<double, 3 > ( 0,0,1 ) {} ;
6 Point2D::Point2D ( const Point2D &p ) : cv::Vec<double,3> ( p ) {};
7 Point2D::Point2D ( const cv::Point &p ) : cv::Vec<double,3> ( p.x,p.y,1. ) {};
8 Point2D::Point2D ( double x, double y ) : cv::Vec<double,3> ( x, y, 1. ) {};
9 Point2D::Point2D ( double x, double y, double h ) : cv::Vec<double,3> ( x, y, h ) {};
10 Point2D::Point2D ( const Polar2D& p ) : cv::Vec<double,3> ( p.rho() * cos ( p.alpha() ), p.rho() * sin ( p.alpha() ), 1 ) {};
17 Point2D &Point2D::set ( double x, double y ) {
18  this->val[0] = x, this->val[1] = y;
19  return *this;
20 }
27 Point2D &Point2D::set ( double x, double y, double h ) {
28  this->val[0] = x, this->val[1] = y, this->val[2] = h;
29  return *this;
30 }
35 const double &Point2D::x () const {
36  return this->val[0];
37 }
42 double &Point2D::x () {
43  return this->val[0];
44 }
49 const double &Point2D::y () const {
50  return this->val[1];
51 }
56 double &Point2D::y () {
57  return this->val[1];
58 }
63 const double &Point2D::h () const {
64  return this->val[2];
65 }
70 double &Point2D::h () {
71  return this->val[2];
72 }
73 
78 void Point2D::set_x ( double v ) {
79  this->x() = v;
80 }
85 double Point2D::get_x () const {
86  return this->x();
87 }
92 void Point2D::set_y ( double v ) {
93  this->y() = v;
94 }
99 double Point2D::get_y () const {
100  return this->y();
101 }
106 void Point2D::set_h ( double v ) {
107  this->h() = v;
108 }
113 double Point2D::get_h () const {
114  return this->h();
115 }
120 cv::Vec<double, 2> Point2D::vector () const {
121  return cv::Vec< double, 2 > ( this->x(), this->y() );
122 }
127 double Point2D::distanceTo ( const Point2D &p ) const {
128  double dx = p.val[0] - this->val[0], dy = p.val[1] - this->val[1];
129  return sqrt ( dx*dx+dy*dy );
130 }
135 const cv::Point_<double> &Point2D::cv () const {
136  return ( cv::Point_<double> & ) *this;
137 }
142 cv::Point_<double> &Point2D::cv () {
143  return ( cv::Point_<double> & ) *this;
144 }
151 double Point2D::angle () const {
152  return atan2 ( this->val[1], this->val[0] );
153 }
160 double Point2D::radius () const {
161  return sqrt ( this->val[0]*this->val[0] + this->val[1]*this->val[1] );
162 }
171 bool Point2D::inside ( double x0, double y0, double x1, double y1 ) const {
172  return ( ( x() >= x0 ) && ( x() <= x1 ) && ( y() >= y0 ) && ( y() <= y1 ) );
173 }
174 
180 std::string Point2D::str(const char* format) const
181 {
182  char str[0xFF];
183  sprintf(str,format, x(), y());
184  return std::string(str);
185 }
186 
192 bool Point2D::equal( const Point2D& o, double tolerance) const {
193  double d = cv::norm(o - *this);
194  return d < tolerance;
195 }
d
const double & y() const
Definition: point2d.cpp:49
double get_h() const
Definition: point2d.cpp:113
bool inside(double x0, double y0, double x1, double y1) const
Definition: point2d.cpp:171
void set_h(double v)
Definition: point2d.cpp:106
cv::Vec< double, 2 > vector() const
Definition: point2d.cpp:120
bool equal(const Point2D &o, double tolerance=0.0001) const
Definition: point2d.cpp:192
Definition: point2d.h:208
const double & h() const
Definition: point2d.cpp:63
double distanceTo(const Point2D &p) const
Definition: point2d.cpp:127
double radius() const
Definition: point2d.cpp:160
Definition: command.h:8
double angle() const
Definition: point2d.cpp:151
double get_y() const
Definition: point2d.cpp:99
void set_x(double v)
Definition: point2d.cpp:78
std::string str(const char *format="[%6.4lf, %6.4lf, %6.5lf]") const
Definition: point2d.cpp:180
const double & x() const
Definition: point2d.cpp:35
std::string format(const cv::Mat_< int8_t > &m)
Definition: utils.cpp:11
void set_y(double v)
Definition: point2d.cpp:92
Point2D & set(double x, double y)
Definition: point2d.cpp:17
double get_x() const
Definition: point2d.cpp:85
const cv::Point_< double > & cv() const
Definition: point2d.cpp:135


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