Files Classes Functions Hierarchy
#include <line.h>
Public Member Functions | |
| line (PT const &nml_, PT const &pos_) | |
| Construct a line from the gradient and an initial point. | |
| line (PT const &p0, PT const &p1, boolc endpoints) | |
| Construct a line from the end points. | |
| void | construct (PT const &nml_, PT const &pos_) |
| Construc the line pos+nml*t. | |
| void | constructfromendpoints (PT const &p0, PT const &p1) |
| Given two points construct the line (p0,p1). | |
| void | normalize () |
| Normalize the gradient. | |
| void | normalize (PD const len) |
| Normalize the gradient to the given length. | |
| PT const | operator() (PD const t) const |
| Line as a parametric equation. | |
| boolc | tD2 (PD &t, PT const &p) const |
| Give a 2D point on the line find its position. | |
| boolc | tD3 (PD &t, PT const &p) const |
| Give a 3D point on the line find its position. | |
| operator stringc () const | |
| Serialize this object by writing it out as a string. | |
| boolc | isnormalzero () const |
| Test for normal before using functions that may divide by zero. | |
| void | nearestpoint (PD &t, PT const &p) const |
| Find the nearest point on the line to p, return the t value. | |
| void | nearestpointcapped (PD &t, PT const &p) const |
| Find the nearest point to the line segment. | |
| void | nearestpoint (PT &q, PT const &p) const |
| Find the nearest point q on the line to p. | |
| boolc | lineD3minimized (PD &t1, PD &t2, line< PT, PD > const &L2) const |
| Minimize two points on lines, t1 is this line and t2 is line L2. | |
| boolc | intersects (PD &t0, PD &t1, line< PT, PD > const &L2) |
| Find the two lines intersection. | |
Static Public Member Functions | |
| static void | nearestpointonline (PT &x, PT const &p, PT const &a, PT const &b) |
| Minimize the distance to point p from point x on line a+b*t. | |
Public Attributes | |
| PT | nml |
| The lines gradient. | |
| PT | pos |
| The start of the line. | |
Optimization Warning: Use this class with caution when optimizing code. This is because the inlining can have a significant impact on performance in a negative way when not done correctly, which is easy to do.
Logic for nml==0 is not supported but this may change.
Definition at line 21 of file line.h.
| void line< PT, PD >::construct | ( | PT const & | nml_, | |
| PT const & | pos_ | |||
| ) | [inline] |
Construc the line pos+nml*t.
Definition at line 167 of file line.h.
References line< PT, PD >::nml, and line< PT, PD >::pos.
| void line< PT, PD >::constructfromendpoints | ( | PT const & | p0, | |
| PT const & | p1 | |||
| ) | [inline] |
Given two points construct the line (p0,p1).
Definition at line 40 of file line.h.
References line< PT, PD >::nml, and line< PT, PD >::pos.
| boolc line< PT, PD >::intersects | ( | PD & | t0, | |
| PD & | t1, | |||
| line< PT, PD > const & | L2 | |||
| ) | [inline] |
Find the two lines intersection.
Definition at line 116 of file line.h.
References solver< T >::d2linearequ(), line< PT, PD >::nml, and line< PT, PD >::pos.
Referenced by linetest::unittest01(), and bsptreeD2< PT, PD, INDX >::validhalfspaces().
00121 { 00122 return solver<PD>::d2linearequ 00123 ( 00124 t0, 00125 t1, 00126 nml.x, 00127 L2.nml.x*((PD)-1.0), 00128 nml.y, 00129 L2.nml.y*((PD)-1.0), 00130 L2.pos.x-pos.x, 00131 L2.pos.y-pos.y 00132 ); 00133 }
Test for normal before using functions that may divide by zero.
Definition at line 63 of file line.h.
References line< PT, PD >::nml.
Referenced by pathlinesegvec::dist01(), and pathlineseg::dist01().
00064 { return zero<PD>::test(nml.dot()); }
| boolc line< PT, PD >::lineD3minimized | ( | PD & | t1, | |
| PD & | t2, | |||
| line< PT, PD > const & | L2 | |||
| ) | const [inline] |
Minimize two points on lines, t1 is this line and t2 is line L2.
Definition at line 143 of file line.h.
References solver< T >::d2linearequ(), line< PT, PD >::nml, and line< PT, PD >::pos.
Referenced by linetest::test02(), and diskinttest::update03lineline().
00148 { 00149 PT C(pos-L2.pos); 00150 PT E1(nml); 00151 PT E2(L2.nml*(-1)); 00152 00153 bool res; 00154 res = solver<PD>::d2linearequ 00155 ( 00156 t1,t2, 00157 E1.dot(),E1.dot(E2), 00158 E1.dot(E2),E2.dot(), 00159 C.dot(E1)*(-1), 00160 C.dot(E2)*(-1) 00161 ); 00162 00163 return res; 00164 }
| void line< PT, PD >::nearestpoint | ( | PT & | q, | |
| PT const & | p | |||
| ) | const [inline] |
Find the nearest point q on the line to p.
Assumes the gradient nml is not zero.
Definition at line 257 of file line.h.
References line< PT, PD >::nml, and line< PT, PD >::pos.
00258 { 00259 assert(zero<PD>::test(nml.dot())==false); 00260 00261 q = pos; 00262 q += nml*(p-pos).dot(nml)/nml.dot(); 00263 }
| void line< PT, PD >::nearestpoint | ( | PD & | t, | |
| PT const & | p | |||
| ) | const [inline] |
Find the nearest point on the line to p, return the t value.
Assumes the gradient nml is not zero. The line points t=0,1 <--> (pos,pos+nml).
Definition at line 239 of file line.h.
References line< PT, PD >::nml, and line< PT, PD >::pos.
Referenced by line< PT, PD >::nearestpointcapped(), and linetest::test01().
00240 { 00241 assert(zero<PD>::test(nml.dot())==false); 00242 00243 t=(p-pos).dot(nml)/nml.dot(); 00244 }
| void line< PT, PD >::nearestpointcapped | ( | PD & | t, | |
| PT const & | p | |||
| ) | const [inline] |
Find the nearest point to the line segment.
The line points t=0,1 <--> (pos,pos+nml).
Definition at line 247 of file line.h.
References line< PT, PD >::nearestpoint().
Referenced by pathlinesegvec::dist01(), pathlineseg::dist01(), and circleD2< PT, PD >::intersects().
00248 { 00249 nearestpoint(t,p); 00250 if (t<((PD)0.0)) 00251 t = (PD)0.0; 00252 if (t>((PD)1.0)) 00253 t = (PD)1.0; 00254 }
| void line< PT, PD >::nearestpointonline | ( | PT & | x, | |
| PT const & | p, | |||
| PT const & | a, | |||
| PT const & | b | |||
| ) | [inline, static] |
Minimize the distance to point p from point x on line a+b*t.
Definition at line 267 of file line.h.
Referenced by triangle3D< PT, PD >::innercircle(), and triangle< PT, PD >::innercircle().
00273 { 00274 assert(zero<PD>::test(b.dot())==false); 00275 x = a + b*( (p-a).dot(b)/(b.dot(b)) ); 00276 }
| void line< PT, PD >::normalize | ( | PD const | len | ) | [inline] |
Normalize the gradient to the given length.
Definition at line 193 of file line.h.
References line< PT, PD >::nml.
| void line< PT, PD >::normalize | ( | ) | [inline] |
Normalize the gradient.
Definition at line 187 of file line.h.
References line< PT, PD >::nml.
Referenced by linetest::test01(), and diskinttest::update03lineline().
00188 { 00189 nml.normalize(); 00190 }
Serialize this object by writing it out as a string.
Definition at line 136 of file line.h.
References line< PT, PD >::nml, and line< PT, PD >::pos.
| PT const line< PT, PD >::operator() | ( | PD const | t | ) | const [inline] |
Line as a parametric equation.
Definition at line 50 of file line.h.
References line< PT, PD >::nml, and line< PT, PD >::pos.
| boolc line< PT, PD >::tD2 | ( | PD & | t, | |
| PT const & | p | |||
| ) | const [inline] |
Give a 2D point on the line find its position.
Definition at line 200 of file line.h.
References line< PT, PD >::nml, and line< PT, PD >::pos.
Referenced by linetest::test01().
00201 { 00202 if (zero<PD>::test(nml.x)) 00203 { 00204 if (zero<PD>::test(nml.y)) 00205 return false; 00206 00207 t = (p.y-pos.y)/nml.y; 00208 } 00209 else 00210 t = (p.x-pos.x)/nml.x; 00211 00212 assert( zero<PD>::test( (operator()(t)-p).dot()) ); 00213 return true; 00214 }
| boolc line< PT, PD >::tD3 | ( | PD & | t, | |
| PT const & | p | |||
| ) | const [inline] |
Give a 3D point on the line find its position.
Definition at line 217 of file line.h.
References line< PT, PD >::nml, and line< PT, PD >::pos.
00218 { 00219 if (zero<PD>::test(nml.x)) 00220 { 00221 if (zero<PD>::test(nml.y)) 00222 { 00223 if (zero<PD>::test(nml.z)) 00224 return false; 00225 00226 t = (p.z-pos.z)/nml.z; 00227 } 00228 else 00229 t = (p.y-pos.y)/nml.y; 00230 } 00231 else 00232 t = (p.x-pos.x)/nml.x; 00233 00234 assert( zero<PD>::test( (operator()(t)-p).dot()) ); 00235 return true; 00236 }
The lines gradient.
Definition at line 26 of file line.h.
Referenced by line< PT, PD >::construct(), line< PT, PD >::constructfromendpoints(), line< PT, PD >::intersects(), circleD2< PT, PD >::intersects(), line< PT, PD >::isnormalzero(), line< PT, PD >::lineD3minimized(), line< PT, PD >::nearestpoint(), line< PT, PD >::normalize(), line< PT, PD >::operator stringc(), line< PT, PD >::operator()(), linechoppedindexed< PT, PD, INDX >::split(), linechopped< PT, PD >::split(), line< PT, PD >::tD2(), line< PT, PD >::tD3(), linetest::test01(), and diskinttest::update03lineline().
The start of the line.
Definition at line 29 of file line.h.
Referenced by line< PT, PD >::construct(), line< PT, PD >::constructfromendpoints(), pathlinesegvec::dist01(), pathlineseg::dist01(), line< PT, PD >::intersects(), circleD2< PT, PD >::intersects(), line< PT, PD >::lineD3minimized(), line< PT, PD >::nearestpoint(), line< PT, PD >::operator stringc(), line< PT, PD >::operator()(), linechoppedindexed< PT, PD, INDX >::split(), linechopped< PT, PD >::split(), line< PT, PD >::tD2(), and line< PT, PD >::tD3().
1.5.8