2 #ifndef vgl_line_2d_hxx_ 3 #define vgl_line_2d_hxx_ 11 # include <vcl_msvc_warnings.h> 20 : a_ ( p1.y() - p2.y() )
21 , b_ ( p2.x() - p1.x() )
22 , c_ ( p1.x() * p2.y() - p1.y() * p2.x() )
32 , c_ ( -a_*p.x() - b_*p.y() )
38 : a_(
l.a()) , b_(
l.b()) , c_(
l.c())
52 if (b() == 0) p1.
set(-c()/a(), 1);
53 else p1.
set(0, -c()/b());
54 if (a() == 0) p2.
set(1, -c()/b());
55 else if ( c() == 0) p2.
set(b(), -a());
56 else p2.
set(-c()/a(), 0);
62 static const double deg_per_rad = 45.0/std::atan2(1.0,1.0);
64 if (a() == 0)
return b()<0 ? 0.0 : 180.0;
65 if (b() == 0)
return a()<0 ? -90.0 : 90.0;
66 if (a() == b())
return a()<0 ? -45.0 : 135.0;
67 if (a()+b() == 0)
return a()<0 ? -135.0 : 45.0;
69 return deg_per_rad * std::atan2(
double(a()),-
double(b()));
75 return std::atan2(
double(a()),-
double(b()));
81 double mag = a_*a_ + b_*b_;
82 if (mag==1.0)
return true;
83 if (mag==0.0)
return false;
84 mag = 1.0/std::sqrt(mag);
90 return mag>0.99 && mag<1.01;
93 #define vp(os,v,s) { (os)<<' '; if ((v)>0) (os)<<'+'; if ((v)&&!(s)[0]) (os)<<(v); else { \ 94 if ((v)==-1) (os)<<'-';\ 95 else if ((v)!=0&&(v)!=1) (os)<<(v);\ 96 if ((v)!=0) (os)<<' '<<(s); } } 102 os <<
"<vgl_line_2d";
vp(os,
l.a(),
"x");
vp(os,
l.b(),
"y");
vp(os,
l.c(),
"");
103 return os <<
" = 0 >";
113 template <
class Type>
116 if (! is.good())
return is;
118 bool formatted =
false;
121 if (is.eof())
return is;
122 if (is.peek() ==
'(') { is.ignore(); paren=
true; }
123 is >> std::ws >> a >> std::ws;
124 if (is.eof())
return is;
125 if (is.peek() ==
',') is.ignore();
126 else if (is.peek() ==
'x') { is.ignore(); formatted=
true; }
127 is >> std::ws >> b >> std::ws;
128 if (is.eof())
return is;
130 if (is.eof())
return is;
131 if (is.peek() ==
'y') is.ignore();
134 else if (is.peek() ==
',') is.ignore();
135 is >> std::ws >> c >> std::ws;
137 if (is.eof())
return is;
138 if (is.peek() ==
')') is.ignore();
142 if (is.eof())
return is;
143 if (is.peek() ==
'=') is.ignore();
146 if (is.peek() ==
'0') is.ignore();
153 #undef VGL_LINE_2D_INSTANTIATE 154 #define VGL_LINE_2D_INSTANTIATE(T) \ 155 template class vgl_line_2d<T >; \ 156 template std::ostream& operator<<(std::ostream&, vgl_line_2d<T >const&); \ 157 template std::istream& operator>>(std::istream&, vgl_line_2d<T >&) 159 #endif // vgl_line_2d_hxx_ a point in 2D nonhomogeneous space
Represents a homogeneous 2D line.
vgl_line_2d()
Default constructor (Line 1.y==0, the X axis).
void set(Type ta, Type tb, Type tc)
Set a b c.
std::ostream & operator<<(std::ostream &s, vgl_orient_box_3d< Type > const &p)
Write box to stream.
line in projective 2D space
bool normalize()
normalize the line coefficients s.t. a^2 + b^2 = 1.
void set(Type px, Type py)
Set x and y.
Represents a Euclidean 2D line.
void get_two_points(vgl_point_2d< Type > &p1, vgl_point_2d< Type > &p2) const
Get two points on the line; normally the intersection with X and Y axes.
double slope_radians() const
angle with the horizontal line y=0, measured in radians.
std::istream & operator>>(std::istream &is, vgl_orient_box_3d< Type > &p)
Read box from stream.
Represents a cartesian 2D point.
double slope_degrees() const
angle with the horizontal line y=0, measured in 360-degrees.