Files Classes Functions Hierarchy
A triangle with ways to calculate many triangle properties. More...
#include <triangle.h>


Public Types | |
| typedef PT | PTtype |
| typedef PD | PDtype |
Public Member Functions | |
| triangle () | |
| Unconstructed triangle. | |
| triangle (PT const &p0, PT const &p1, PT const &p2) | |
| Construct from anti clockwise point ordering. | |
| void | construct (PT const &p0, PT const &p1, PT const &p2) |
| Construct from anti clockwise point ordering. | |
| void | constructUnordered (PT const &p0, PT const &p1, PT const &p2) |
| No guarantee of point order because of swapping. | |
| void | bisectangle (PT &x, uintc i) const |
| From vertex i extend a line bisecting the angle in half. | |
| void | centroid (PT &x) const |
| Calculate the Centroid. | |
| void | circumcenter (PT &x) const |
| Calculate the Circumcenter. | |
| void | equilaterali (PT &x, uintc i) const |
| Gets the gradient opposite the vertex i. | |
| void | fermatpoint (PT &x) const |
| From the edge construct an equilateral triangle and intersect its extreme vertexes with the opposite point. | |
| void | gergonnepoint (PT &x) const |
| Intersection of bisectors with opposite points. | |
| void | incenter (PT &x) const |
| Calculate the Incenter. | |
| void | incenteri (PT &x, uint i) const |
| Calculate the point of the inner circle on side i. | |
| template<typename U > | |
| void | innercircle (PD &radius, U ¢er, U &circlenormal) const |
| Find the circle inside the triangle touching all sides. | |
| void | midpoint (PT &x, uintc i) const |
| Calculate the midpoint opposite the vertex i. | |
| template<typename U > | |
| void | normal (U &circlenormal) const |
| Normal in 3D space. | |
| void | napoleanpoint (PT &x) const |
| Find the centroids of equilateral triangles constructed on edges. | |
| void | orthocenter (PT &x) const |
| Calculate the Orthocenter. | |
| void | orthocenteri (PT &x, uintc i) const |
| From the indexed point i construct a line to the opposite side intersecting at right angles, calculate this point. | |
| template<typename U > | |
| void | outercircle (PD &radius, U ¢er, U &circlenormal) const |
| Find the circle passing though all the points. | |
| void | outercircle (PD &radius, PT ¢er) const |
| Find the circle passing though all the points. | |
| boolc | valid () const |
| Assert if the triangle is invalid. | |
Public Attributes | |
| PT | pi [3] |
| The three points of the triangle. | |
A triangle with ways to calculate many triangle properties.
Many geometric properties such as the orthocenter, centroid and circumcenter can be calculated.
This is a monolith design. Each property could be made its own class but I want efficiency.
The class is deliberately designed without virtual functions or inheritance for efficiency.
Definition at line 25 of file triangle.h.
Definition at line 30 of file triangle.h.
Definition at line 29 of file triangle.h.
| triangle< PT, PD >::triangle | ( | PT const & | p0, | |
| PT const & | p1, | |||
| PT const & | p2 | |||
| ) | [inline] |
Construct from anti clockwise point ordering.
Definition at line 533 of file triangle.h.
00538 { 00539 construct(_p0,_p1,_p2); 00540 }
| void triangle< PT, PD >::bisectangle | ( | PT & | x, | |
| uintc | i | |||
| ) | const [inline] |
From vertex i extend a line bisecting the angle in half.
Return where this line intersects the triangles edge.
Definition at line 349 of file triangle.h.
References triangle< PT, PD >::pi.
Referenced by trianglevisualize< T >::eval(), and triangle< PT, PD >::incenter().
00350 { 00351 PT A,B; 00352 PT X; 00353 00354 switch(i) 00355 { 00356 case 0: 00357 A = pi[1]; 00358 B = pi[2]; 00359 X = pi[0]; 00360 break; 00361 00362 case 1: 00363 A = pi[0]; 00364 B = pi[2]; 00365 X = pi[1]; 00366 break; 00367 00368 case 2: 00369 A = pi[1]; 00370 B = pi[0]; 00371 X = pi[2]; 00372 break; 00373 00374 00375 default: 00376 assert(false); 00377 } 00378 00379 PD a = (A-X).distance(); 00380 PD b = (B-X).distance(); 00381 00382 x = (A*b+B*a)/(a+b); 00383 }
| void triangle< PT, PD >::centroid | ( | PT & | x | ) | const [inline] |
Calculate the Centroid.
Definition at line 340 of file triangle.h.
References triangle< PT, PD >::pi.
Referenced by triangle< PT, PD >::circumcenter(), and trianglevisualize< T >::eval().
| void triangle< PT, PD >::circumcenter | ( | PT & | x | ) | const [inline] |
Calculate the Circumcenter.
Definition at line 314 of file triangle.h.
References triangle< PT, PD >::centroid(), and triangle< PT, PD >::orthocenter().
Referenced by trianglevisualize< T >::eval().
00315 { 00316 //x =(G*3.0-H)*0.5; 00317 centroid(x); 00318 x *= 3.0; 00319 PT H; 00320 orthocenter(H); 00321 x -= H; 00322 x *= 0.5; 00323 }
| void triangle< PT, PD >::construct | ( | PT const & | p0, | |
| PT const & | p1, | |||
| PT const & | p2 | |||
| ) | [inline] |
| void triangle< PT, PD >::constructUnordered | ( | PT const & | p0, | |
| PT const & | p1, | |||
| PT const & | p2 | |||
| ) | [inline] |
| void triangle< PT, PD >::equilaterali | ( | PT & | x, | |
| uintc | i | |||
| ) | const [inline] |
Gets the gradient opposite the vertex i.
Gets invards pointing normal opposite the vertex i. Get the point forming an equilateral triangle with the opposite side.
Definition at line 386 of file triangle.h.
References triangle< PT, PD >::pi.
Referenced by triangle< PT, PD >::fermatpoint(), and triangle< PT, PD >::napoleanpoint().
00387 { 00388 PT g; 00389 PT n1; 00390 switch(i) 00391 { 00392 case 0: 00393 g = (pi[2]+pi[1])*0.5; 00394 n1=pi[2]-pi[1]; 00395 break; 00396 case 1: 00397 g = (pi[2]+pi[0])*0.5; 00398 n1=pi[0]-pi[2]; 00399 break; 00400 case 2: 00401 g = (pi[0]+pi[1])*0.5; 00402 n1=pi[1]-pi[0]; 00403 break; 00404 default: 00405 assert(false); 00406 } 00407 00408 // Outwards normal. 00409 PT n2(n1.y,-n1.x); 00410 n2.normalize(); 00411 00412 x = g+n2*sqrt(3.0)*0.5*n1.distance(); 00413 }
| void triangle< PT, PD >::fermatpoint | ( | PT & | x | ) | const [inline] |
From the edge construct an equilateral triangle and intersect its extreme vertexes with the opposite point.
Definition at line 202 of file triangle.h.
References d2matsolve(), triangle< PT, PD >::equilaterali(), and triangle< PT, PD >::pi.
00203 { 00204 PT e0; 00205 equilaterali(e0,0); 00206 PT e1; 00207 equilaterali(e1,1); 00208 00209 PT t; 00210 d2matsolve(t,pi[0]-e0,e1-pi[1],e1-e0); 00211 00212 x = e0 + (pi[0]-e0)*t.x; 00213 }
| void triangle< PT, PD >::gergonnepoint | ( | PT & | x | ) | const [inline] |
Intersection of bisectors with opposite points.
Definition at line 168 of file triangle.h.
References d2matsolve(), triangle< PT, PD >::incenteri(), and triangle< PT, PD >::pi.
| void triangle< PT, PD >::incenter | ( | PT & | x | ) | const [inline] |
Calculate the Incenter.
Definition at line 216 of file triangle.h.
References triangle< PT, PD >::bisectangle(), d2matsolve(), and triangle< PT, PD >::pi.
00217 { 00218 PT b0; 00219 bisectangle(b0,0); 00220 PT b1; 00221 bisectangle(b1,1); 00222 00223 PT v; // The two variables. 00224 d2matsolve 00225 ( 00226 v, 00227 b0 - pi[0], pi[1] - b1, 00228 pi[1] - pi[0] 00229 ); 00230 00231 x = pi[0]+(b0-pi[0])*v.x; 00232 }
Calculate the point of the inner circle on side i.
Referenced by triangle< PT, PD >::gergonnepoint().
| void triangle< PT, PD >::innercircle | ( | PD & | radius, | |
| U & | center, | |||
| U & | circlenormal | |||
| ) | const [inline] |
Find the circle inside the triangle touching all sides.
Definition at line 246 of file triangle.h.
References line< PT, PD >::nearestpointonline().
Referenced by trianglevisualize< T >::eval().
| void triangle< PT, PD >::midpoint | ( | PT & | x, | |
| uintc | i | |||
| ) | const [inline] |
Calculate the midpoint opposite the vertex i.
Definition at line 493 of file triangle.h.
References triangle< PT, PD >::pi.
Referenced by trianglevisualize< T >::eval().
| void triangle< PT, PD >::napoleanpoint | ( | PT & | x | ) | const [inline] |
Find the centroids of equilateral triangles constructed on edges.
Intersect lines from centroid to opposite point on triangle.
Definition at line 182 of file triangle.h.
References d2matsolve(), triangle< PT, PD >::equilaterali(), and triangle< PT, PD >::pi.
00183 { 00184 PT c0; 00185 equilaterali(c0,0); 00186 c0 += pi[1]; 00187 c0 += pi[2]; 00188 c0 /= 3.0; 00189 PT c1; 00190 equilaterali(c1,1); 00191 c1 += pi[0]; 00192 c1 += pi[2]; 00193 c1 /= 3.0; 00194 00195 PT t; 00196 d2matsolve(t,pi[0]-c0,c1-pi[1],c1-c0); 00197 00198 x = c0 + (pi[0]-c0)*t.x; 00199 }
| void triangle< PT, PD >::normal | ( | U & | circlenormal | ) | const [inline] |
Normal in 3D space.
Definition at line 235 of file triangle.h.
| void triangle< PT, PD >::orthocenter | ( | PT & | x | ) | const [inline] |
Calculate the Orthocenter.
Definition at line 326 of file triangle.h.
References d2matsolve(), triangle< PT, PD >::orthocenteri(), and triangle< PT, PD >::pi.
Referenced by triangle< PT, PD >::circumcenter(), and trianglevisualize< T >::eval().
00327 { 00328 PT p0w; 00329 orthocenteri(p0w,0); 00330 PT p1w; 00331 orthocenteri(p1w,1); 00332 PT t; 00333 00334 d2matsolve(t,p0w-pi[0],pi[1]-p1w,pi[1]-pi[0]); 00335 00336 x = pi[0] + (p0w-pi[0])*t.x; 00337 }
| void triangle< PT, PD >::orthocenteri | ( | PT & | x, | |
| uintc | i | |||
| ) | const [inline] |
From the indexed point i construct a line to the opposite side intersecting at right angles, calculate this point.
Definition at line 452 of file triangle.h.
References d2matsolve(), and triangle< PT, PD >::pi.
Referenced by trianglevisualize< T >::eval(), and triangle< PT, PD >::orthocenter().
00453 { 00454 PT z; 00455 PT m0; 00456 PT w0; 00457 00458 switch(i) 00459 { 00460 case 0: 00461 w0 = pi[1]; 00462 m0 = pi[2] - pi[1]; 00463 00464 z = pi[0]; 00465 break; 00466 00467 case 1: 00468 w0 = pi[2]; 00469 m0 = pi[0] - pi[2]; 00470 00471 z = pi[1]; 00472 break; 00473 00474 case 2: 00475 w0 = pi[0]; 00476 m0 = pi[1] - pi[0]; 00477 00478 z = pi[2]; 00479 break; 00480 00481 default: 00482 assert(false); 00483 } 00484 00485 PT m1(-m0.y,m0.x); 00486 PT t; 00487 d2matsolve(t,m0,m1*-1.0,z-w0); 00488 00489 x = z + m1*t.y; 00490 }
| void triangle< PT, PD >::outercircle | ( | PD & | radius, | |
| PT & | center | |||
| ) | const [inline] |
Find the circle passing though all the points.
Definition at line 300 of file triangle.h.
00304 { 00305 PT c; 00306 circumcenter(c); 00307 center.x = c.x; 00308 center.y = c.y; 00309 radius = (c-pi[0]).distance(); 00310 }
| void triangle< PT, PD >::outercircle | ( | PD & | radius, | |
| U & | center, | |||
| U & | circlenormal | |||
| ) | const [inline] |
Find the circle passing though all the points.
Definition at line 284 of file triangle.h.
Referenced by tessD2draw02circles< TESS, PT, INDX >::draw(), writecirclesobj::draw(), writecpcircleobj::draw(), and tessD2disp01< PT >::eval().
00289 { 00290 PT c; 00291 circumcenter(c); 00292 center.x = c.x; 00293 center.y = c.y; 00294 radius = (c-pi[0]).distance(); 00295 normal(circlenormal); 00296 }
Assert if the triangle is invalid.
Definition at line 543 of file triangle.h.
References triangle< PT, PD >::pi.
The three points of the triangle.
Definition at line 33 of file triangle.h.
Referenced by triangle< PT, PD >::bisectangle(), triangle< PT, PD >::centroid(), triangle< PT, PD >::equilaterali(), trianglevisualize< T >::eval(), tessD2disp01< PT >::eval(), triangle< PT, PD >::fermatpoint(), triangle< PT, PD >::gergonnepoint(), triangle< PT, PD >::incenter(), triangle< PT, PD >::midpoint(), triangle< PT, PD >::napoleanpoint(), triangle< PT, PD >::orthocenter(), triangle< PT, PD >::orthocenteri(), and triangle< PT, PD >::valid().
1.6.1