proj home

Files   Classes   Functions   Hierarchy  

triangle3D< PT, PD > Class Template Reference

A triangle in 3D with ways to calculate many triangle properties. More...

#include <triangle3D.h>

Inheritance diagram for triangle3D< PT, PD >:
Collaboration diagram for triangle3D< PT, PD >:

List of all members.

Public Types

typedef PT PTtype
typedef PD PDtype

Public Member Functions

 triangle3D ()
 Unconstructed triangle.
 triangle3D (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 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, uint i) const
 Get the point forming an equilateral triangle with the opposite side.
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.
void innercircle (PD &radius, PT &center, PT &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.
void napoleanpoint (PT &x) const
 Find the centroids of equilateral triangles constructed on edges.
void normali (PT &x, uintc i) const
 Find the normal of the side opposite the i'th vertex.
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.
void orthocenter (PT &x) const
 Calculate the Orthocenter.
template<typename U >
void normal (U &w) const
 Normal in 3D space.
template<typename U >
void outercircle (PD &radius, U &center, U &circlenormal) const
 Find the circle passing though all the points.
boolc valid () const
 No testing, recommend test at construction context.

Public Attributes

PT pi [3]
 The three points of the triangle.


Detailed Description

template<typename PT, typename PD>
class triangle3D< PT, PD >

A triangle in 3D with ways to calculate many triangle properties.

The class is deliberately designed without virtual functions or inheritance for efficiency.

Definition at line 14 of file triangle3D.h.


Member Typedef Documentation

template<typename PT, typename PD>
typedef PD triangle3D< PT, PD >::PDtype

Definition at line 19 of file triangle3D.h.

template<typename PT, typename PD>
typedef PT triangle3D< PT, PD >::PTtype

Definition at line 18 of file triangle3D.h.


Constructor & Destructor Documentation

template<typename PT, typename PD>
triangle3D< PT, PD >::triangle3D (  )  [inline]

Unconstructed triangle.

Definition at line 25 of file triangle3D.h.

00025 {}

template<typename PT, typename PD >
triangle3D< PT, PD >::triangle3D ( PT const &  p0_,
PT const &  p1_,
PT const &  p2_ 
) [inline]

Construct from anti clockwise point ordering.

Definition at line 214 of file triangle3D.h.

00219 {
00220   construct(p0_,p1_,p2_);
00221 }


Member Function Documentation

template<typename PT, typename PD >
void triangle3D< 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 318 of file triangle3D.h.

References triangle3D< PT, PD >::pi.

Referenced by triangle3D< PT, PD >::incenter().

00319 {
00320   PT A,B;
00321   PT X;
00322 
00323   switch(i)
00324   {
00325     case 0:
00326       A = pi[1];
00327       B = pi[2];
00328       X = pi[0];
00329       break;
00330 
00331     case 1:
00332       A = pi[0];
00333       B = pi[2];
00334       X = pi[1];
00335       break;
00336 
00337     case 2:
00338       A = pi[1];
00339       B = pi[0];
00340       X = pi[2];
00341       break;
00342 
00343     default:
00344       assert(false);
00345   }
00346 
00347   PD a = (A-X).distance();
00348   PD b = (B-X).distance();
00349 
00350   x = (A*b+B*a)/(a+b);
00351 }

template<typename PT, typename PD >
void triangle3D< PT, PD >::centroid ( PT &  x  )  const [inline]

Calculate the Centroid.

Definition at line 177 of file triangle3D.h.

References triangle3D< PT, PD >::pi.

Referenced by triangle3D< PT, PD >::circumcenter(), and tetrahedron< PT, PD >::equilaterali().

00178 {
00179   x =  pi[0];
00180   x += pi[1];
00181   x += pi[2];
00182   x /= 3.0;
00183 }

template<typename PT, typename PD >
void triangle3D< PT, PD >::circumcenter ( PT &  x  )  const [inline]

Calculate the Circumcenter.

Definition at line 186 of file triangle3D.h.

References triangle3D< PT, PD >::centroid(), and triangle3D< PT, PD >::orthocenter().

00187 {
00188   //x =(G*3.0-H)*0.5;
00189   centroid(x);
00190   x *= 3.0;
00191   PT H;
00192   orthocenter(H);
00193   x -= H;
00194   x *= 0.5;
00195 }

template<typename PT, typename PD >
void triangle3D< PT, PD >::construct ( PT const &  p0_,
PT const &  p1_,
PT const &  p2_ 
) [inline]

Construct from anti clockwise point ordering.

Definition at line 199 of file triangle3D.h.

Referenced by tetrahedron< PT, PD >::trianglei().

00204 {
00205   pi[0] = p0_;
00206   pi[1] = p1_;
00207   pi[2] = p2_;
00208 
00209   valid();
00210 }

template<typename PT, typename PD >
void triangle3D< PT, PD >::equilaterali ( PT &  x,
uint  i 
) const [inline]

Get the point forming an equilateral triangle with the opposite side.

Definition at line 230 of file triangle3D.h.

References crossproduct::evalxyz(), triangle3D< PT, PD >::normal(), and triangle3D< PT, PD >::pi.

Referenced by triangle3D< PT, PD >::fermatpoint(), and triangle3D< PT, PD >::napoleanpoint().

00231 {
00232   PT g;
00233   PT n1;
00234   switch(i)
00235   {
00236     case 0:
00237       g = (pi[2]+pi[1])*0.5;
00238       n1=pi[2]-pi[1];
00239       break;
00240     case 1:
00241       g = (pi[2]+pi[0])*0.5;
00242       n1=pi[0]-pi[2];
00243       break;
00244     case 2:
00245       g = (pi[0]+pi[1])*0.5;
00246       n1=pi[1]-pi[0];
00247       break;
00248     default:
00249       assert(false);
00250   }
00251   PT nml;
00252   normal(nml);
00253   PT n2;
00254   crossproduct::evalxyz(n2,n1,nml);
00255   assert(n2.distance()!=0);
00256   n2 /= n2.distance();
00257   x = g+n2*sqrt(3.0)*0.5*n1.distance();
00258 }

template<typename PT, typename PD >
void triangle3D< 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 304 of file triangle3D.h.

References d2matsolve3D(), triangle3D< PT, PD >::equilaterali(), and triangle3D< PT, PD >::pi.

00305 {
00306   PT c0;
00307   equilaterali(c0,0);
00308   PT c1;
00309   equilaterali(c1,1);
00310 
00311   PT t;
00312   d2matsolve3D(t, pi[1]-c1, c0-pi[0], c0-c1);
00313 
00314   x = c1 + (pi[1]-c1)*t.x;
00315 }

template<typename PT, typename PD >
void triangle3D< PT, PD >::gergonnepoint ( PT &  x  )  const [inline]

Intersection of bisectors with opposite points.

Definition at line 378 of file triangle3D.h.

References d2matsolve3D(), triangle3D< PT, PD >::incenteri(), and triangle3D< PT, PD >::pi.

00379 {
00380   PT c0; 
00381   incenteri(c0,0);
00382   PT c1; 
00383   incenteri(c1,1);
00384 
00385   PT t;
00386   d2matsolve3D(t,pi[0]-c0,c1-pi[1],c1-c0);
00387 
00388   x = c0 + (pi[0]-c0)*t.x;
00389 }

template<typename PT, typename PD >
void triangle3D< PT, PD >::incenter ( PT &  x  )  const [inline]

Calculate the Incenter.

Definition at line 392 of file triangle3D.h.

References triangle3D< PT, PD >::bisectangle(), d2matsolve3D(), and triangle3D< PT, PD >::pi.

00393 {
00394   PT b0;
00395   bisectangle(b0,0);
00396   PT b1;
00397   bisectangle(b1,1);
00398 
00399   PT v;  // The two variables. 
00400   d2matsolve3D
00401   (
00402     v,
00403     b0 - pi[0], pi[1] - b1,
00404     pi[1] - pi[0]
00405   );
00406 
00407   x = pi[0]+(b0-pi[0])*v.x;
00408 }

template<typename PT, typename PD>
void triangle3D< PT, PD >::incenteri ( PT &  x,
uint  i 
) const

Calculate the point of the inner circle on side i.

Referenced by triangle3D< PT, PD >::gergonnepoint().

template<typename PT, typename PD>
void triangle3D< PT, PD >::innercircle ( PD &  radius,
PT &  center,
PT &  circlenormal 
) const [inline]

Find the circle inside the triangle touching all sides.

Definition at line 428 of file triangle3D.h.

References line< PT, PD >::nearestpointonline().

00433 {
00434   incenter(center);
00435 
00436   PT w;
00437   line<PT,PD>::nearestpointonline(w,center,pi[0],pi[1]-pi[0]);
00438 //cout << SHOW(w) << endl;
00439   w -= center;
00440 
00441   radius = w.distance();
00442 
00443   normal(circlenormal);
00444 /*
00445 cout << SHOW(pi[0]) << " ";
00446 cout << SHOW(pi[1]) << " ";
00447 cout << SHOW(pi[2]) << " ";
00448 cout << endl;
00449 cout << SHOW(radius) << endl;
00450 cout << SHOW(center) << endl;
00451 cout << SHOW(circlenormal) << endl;
00452 */
00453 }

template<typename PT, typename PD >
void triangle3D< PT, PD >::midpoint ( PT &  x,
uintc  i 
) const [inline]

Calculate the midpoint opposite the vertex i.

Definition at line 354 of file triangle3D.h.

References triangle3D< PT, PD >::pi.

00355 {
00356   switch(i)
00357   {
00358     case 0:
00359       x=pi[1]; x += pi[2]; 
00360       break;
00361 
00362     case 1:
00363       x=pi[0]; x += pi[2]; 
00364       break;
00365 
00366     case 2:
00367       x=pi[1]; x += pi[0];
00368       break;
00369       
00370     default:
00371       assert(false);
00372   }
00373 
00374   x *= 0.5;
00375 }

template<typename PT, typename PD >
void triangle3D< 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 277 of file triangle3D.h.

References d2matsolve3D(), triangle3D< PT, PD >::equilaterali(), and triangle3D< PT, PD >::pi.

00278 {
00279   PT e0;
00280   equilaterali(e0,0);
00281   PT e1;
00282   equilaterali(e1,1);
00283 
00284   PD a(1.0);
00285   a /= PD(3.0);
00286 
00287   PT c0(e0);
00288   c0 += pi[1];
00289   c0 += pi[2];
00290   c0 *= a;
00291 
00292   PT c1(e1);
00293   c1 += pi[0];
00294   c1 += pi[2];
00295   c1 *= a;
00296 
00297   PT t;
00298   d2matsolve3D(t, pi[1]-c1, c0-pi[0], c0-c1);
00299 
00300   x = c1 + (pi[1]-c1)*t.x;
00301 }

template<typename PT, typename PD>
template<typename U >
void triangle3D< PT, PD >::normal ( U &  w  )  const [inline]

Normal in 3D space.

Definition at line 96 of file triangle3D.h.

Referenced by triangle3D< PT, PD >::equilaterali(), tetrahedron< PT, PD >::equilaterali(), and triangle3D< PT, PD >::orthocenteri().

00097     { crossproduct::evalxyz(w, pi[1]-pi[0], pi[2]-pi[0]); }

template<typename PT, typename PD >
void triangle3D< PT, PD >::normali ( PT &  x,
uintc  i 
) const [inline]

Find the normal of the side opposite the i'th vertex.

Definition at line 138 of file triangle3D.h.

References crossproduct::evalxyz(), and triangle3D< PT, PD >::pi.

00139 {
00140   switch(i)
00141   {
00142     case 0: 
00143       crossproduct::evalxyz(x, pi[2]-pi[1], pi[0]-pi[2]); break;
00144 
00145     case 1: 
00146       crossproduct::evalxyz(x, pi[0]-pi[2], pi[1]-pi[0]); break;
00147 
00148     case 2: 
00149       crossproduct::evalxyz(x, pi[1]-pi[0], pi[2]-pi[1] ); break;
00150 
00151     default:
00152       assert(false);
00153   }
00154 } 

template<typename PT, typename PD >
void triangle3D< PT, PD >::orthocenter ( PT &  x  )  const [inline]

Calculate the Orthocenter.

Definition at line 261 of file triangle3D.h.

References d2matsolve3D(), triangle3D< PT, PD >::orthocenteri(), and triangle3D< PT, PD >::pi.

Referenced by triangle3D< PT, PD >::circumcenter().

00262 {
00263   PT t;
00264   PT p0w;
00265   orthocenteri(p0w,0);
00266 //cout << SHOW(p0w) << endl;
00267   PT p1w;
00268   orthocenteri(p1w,1);
00269 //cout << SHOW(p1w) << endl;
00270 
00271   d2matsolve3D(t, p0w-pi[0], pi[1]-p1w, pi[1]-pi[0]);
00272 
00273   x = pi[0] + (p0w-pi[0])*t.x;
00274 }

template<typename PT, typename PD >
void triangle3D< 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 157 of file triangle3D.h.

References asserteval, d2matsolve3D(), crossproduct::evalxyz(), triangle3D< PT, PD >::normal(), and triangle3D< PT, PD >::pi.

Referenced by triangle3D< PT, PD >::orthocenter().

00158 {
00159   assert(i<3);
00160 
00161   PT w0(pi[(i+1)%3]);
00162   PT w(pi[(i+2)%3]-w0);
00163   PT nml;
00164   normal(nml);
00165 //cout << SHOW(nml) << endl;
00166   PT m1;
00167   crossproduct::evalxyz(m1, w, nml);
00168 //cout << SHOW(m1) << endl;
00169 
00170   PT t;
00171   asserteval(d2matsolve3D(t,m1,w*-1.0,w0-pi[i]));
00172 
00173   x = pi[i] + m1*t.x;
00174 }

template<typename PT , typename PD>
template<typename U >
void triangle3D< PT, PD >::outercircle ( PD &  radius,
U &  center,
U &  circlenormal 
) const [inline]

Find the circle passing though all the points.

Definition at line 126 of file triangle3D.h.

00131 {
00132   circumcenter(center);
00133   radius = (center-pi[0]).distance();
00134   normal(circlenormal);
00135 }

template<typename PT , typename PD >
boolc triangle3D< PT, PD >::valid (  )  const [inline]

No testing, recommend test at construction context.

Definition at line 224 of file triangle3D.h.

00225 {
00226   return true;
00227 }


Member Data Documentation

template<typename PT, typename PD>
PT triangle3D< PT, PD >::pi[3]


The documentation for this class was generated from the following file:

Generated on Fri Mar 4 00:50:21 2011 for Chelton Evans Source by  doxygen 1.5.8