proj home

Files   Classes   Functions   Hierarchy  

tetrahedron< PT, PD > Class Template Reference

Tetrahedron properties. More...

#include <tetrahedron.h>

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

List of all members.

Public Types

typedef PT PTtype
typedef PD PDtype
typedef void(triangle3D< PT,
PD >::* 
Fptr )(PT &) const

Public Member Functions

 tetrahedron ()
 Unconstructed tetrahedron.
 tetrahedron (PT const &p0_, PT const &p1_, PT const &p2_, PT const &p3_)
 The first three points form the inner base with a clockwise winding.
void construct (PT const &p0_, PT const &p1_, PT const &p2_, PT const &p3_)
 The first three points form the inner base with a clockwise winding.
void constructUnordered (PT const &p0_, PT const &p1_, PT const &p2_, PT const &p3_)
 A tetrahedron is formed, but there is no guarantee of point order as they are swapped to get a correctly ordered tetrahedron.
void centroid (PT &x) const
 The average of the four points.
void equilaterali (PT &x, uint i) const
 Generalizing the equilateral triangle to a tetrahedron, i indexes the face opposite point i, construct a point which has all sides of the new tetrahedron with the same triangle.
void circumcenter (PT &x) const
 Center of sphere.
void circumcenter (PT &x, uintc i) const
 Center of triangle opposite vertex i.
void verticiespoint (PT &x, uintc i) const
void triangleverticiespoint (PT &x, uintc i) const
 Calculate the altitude to point on a triangle face.
void trianglei (triangle3D< PT, PD > &x, uintc i) const
 From vertex i extend a line bisecting the angle in half.
boolc valid () const
 If the point representation is invalid and NDEBUG is not definded the function asserts.
void applytoself (tetrahedron< PT, PD > &tet, Fptr fn) const
 Apply a function to generate a point from each side of the tetrahedron from the 3D triangle, the four points form another tetrahedron.
void applytoself (tetrahedron< PT, PD > &tet, Fptr fn, uintc n) const

Public Attributes

PT pi [4]
 The four points of the tetrahedron.


Detailed Description

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

Tetrahedron properties.

PT is the point type. PD is the data type comprising the point.

Definition at line 21 of file tetrahedron.h.


Member Typedef Documentation

template<typename PT, typename PD>
typedef void(triangle3D<PT,PD>::* tetrahedron< PT, PD >::Fptr)(PT &) const

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

Definition at line 26 of file tetrahedron.h.

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

Definition at line 25 of file tetrahedron.h.


Constructor & Destructor Documentation

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

Unconstructed tetrahedron.

Definition at line 32 of file tetrahedron.h.

00032 {}

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

The first three points form the inner base with a clockwise winding.

Definition at line 537 of file tetrahedron.h.

00543 {
00544   construct(p0,p1,p2,p3);
00545 }


Member Function Documentation

template<typename PT, typename PD>
void tetrahedron< PT, PD >::applytoself ( tetrahedron< PT, PD > &  tet,
Fptr  fn,
uintc  n 
) const

template<typename PT, typename PD>
void tetrahedron< PT, PD >::applytoself ( tetrahedron< PT, PD > &  tet,
Fptr  fn 
) const

Apply a function to generate a point from each side of the tetrahedron from the 3D triangle, the four points form another tetrahedron.

Referenced by tetrahedrontest::test02().

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

The average of the four points.

Definition at line 220 of file tetrahedron.h.

References tetrahedron< PT, PD >::pi.

00221 {
00222   x = pi[0];
00223   x += pi[1];
00224   x += pi[2];
00225   x += pi[3];
00226   x *= 0.25;
00227 }

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

Center of triangle opposite vertex i.

Definition at line 282 of file tetrahedron.h.

00283 {
00284 assert(false);
00285 /*
00286 // <TODO>
00287 //  T N3(hi[i].nml);
00288 
00289   T a(pi[(i+1)%4]);
00290   T b(pi[(i+2)%4]);
00291   T c(pi[(i+3)%4]);
00292 
00293   crossprod< T > cross;
00294   T N1,N2;
00295   cross( N1, a-b, N3 );
00296   cross( N2, c-b, N3 );
00297 
00298   T mba = (b+a)*0.5;
00299   T mbc = (b+c)*0.5;
00300 
00301   T t0, t1;
00302 
00303   d2matsolve
00304   (
00305     t0, t1,
00306     N1.x, -N2.x, 
00307     N1.y, -N2.y, 
00308     mbc.x - mba.x,
00309     mbc.y - mba.y
00310   );
00311 
00312   return N1*t0 + mba;
00313 */
00314 }

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

Center of sphere.

ie distances to verticies are all equal.

Definition at line 244 of file tetrahedron.h.

References gausselim< T >::columnC(), gausselim< T >::eval(), and tetrahedron< PT, PD >::pi.

Referenced by visualize_tetrahedron< T >::eval(), and cpsphere::update().

00245 {
00246   // Translate the points : p[0] is at the origin.
00247   PT p[4];
00248   for (uint i=0; i<4; ++i)
00249   {
00250     p[i] = pi[i];
00251     p[i] -= pi[0];
00252   };
00253 
00254   PD e[] = 
00255   {
00256     p[1].x, p[1].y, p[1].z, p[1].dot()*0.5,
00257     p[2].x, p[2].y, p[2].z, p[2].dot()*0.5,
00258     p[3].x, p[3].y, p[3].z, p[3].dot()*0.5
00259   };
00260 
00261   //gausselim<PD,3> g(e,1E-15);
00262   gausselim<PD> g(e,3);
00263 //cout << "Initial system" << endl;
00264 //  g.print();
00265   g.eval();
00266 //cout << "Solve system." << endl;
00267 //g.print();
00268 
00269   PD s[3];
00270   g.columnC(s);
00271 
00272   x = pi[0];
00273   x.x += s[0];
00274   x.y += s[1];
00275   x.z += s[2];
00276   
00277 //  return pi[0]+(PT)(s[0],s[1],s[2]);
00278 }

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

The first three points form the inner base with a clockwise winding.

Definition at line 549 of file tetrahedron.h.

00555 {
00556   pi[0] = p0;
00557   pi[1] = p1;
00558   pi[2] = p2;
00559   pi[3] = p3;
00560 
00561   assert(valid());
00562 }

template<typename PT, typename PD >
void tetrahedron< PT, PD >::constructUnordered ( PT const &  p0_,
PT const &  p1_,
PT const &  p2_,
PT const &  p3_ 
) [inline]

A tetrahedron is formed, but there is no guarantee of point order as they are swapped to get a correctly ordered tetrahedron.

Definition at line 566 of file tetrahedron.h.

00572 {
00573   pi[0] = p0;
00574   pi[1] = p1;
00575   pi[2] = p2;
00576   pi[3] = p3;
00577 
00578   if (valid()==false)
00579   {
00580     pi[0] = p2;
00581     pi[2] = p0;
00582 
00583     assert(valid());
00584   }
00585 }

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

Generalizing the equilateral triangle to a tetrahedron, i indexes the face opposite point i, construct a point which has all sides of the new tetrahedron with the same triangle.

Definition at line 170 of file tetrahedron.h.

References triangle3D< PT, PD >::centroid(), triangle3D< PT, PD >::normal(), triangle3D< PT, PD >::pi, solvequadratic(), and tetrahedron< PT, PD >::trianglei().

00171 {
00172   triangle3D<PT,PD> w;
00173   trianglei(w,i);
00174   PT a;
00175   w.centroid(a);
00176   PT b;
00177   w.normal(b);
00178   PT a2(a-w.pi[0]);
00179   // The distance between point 1 and 2, squared.
00180   PD l0 = (w.pi[1]-w.pi[2]).dot();
00181 
00182   // Currently must solve in doubles.
00183   PD t0;
00184   PD t1;
00185   //double t0;
00186   //double t1;
00187   solvequadratic(t0,t1,b.dot(),a2.dot(b)*2.0,a2.dot()-l0);
00188   PD t=t0;
00189   if (t<0)
00190     t=t1;
00191   assert(t>0);
00192 
00193   x = a+b*t;
00194 }

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

From vertex i extend a line bisecting the angle in half.

Return where this line intersects the triangles edge. The triangle opposite the point i with anticlockwise point ordering facing outside the tetrahedron, arbitary orientation.

Definition at line 198 of file tetrahedron.h.

References triangle3D< PT, PD >::construct(), halfspaceD3< PT, PD >::isInside(), and triangle3D< PT, PD >::pi.

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

00202 {
00203   PT q;
00204   switch (i)
00205   {
00206     case 0: x.construct(pi[3],pi[2],pi[1]); break;
00207     case 1: x.construct(pi[0],pi[2],pi[3]); break;
00208     case 2: x.construct(pi[1],pi[0],pi[3]); break;
00209     case 3: x.construct(pi[0],pi[1],pi[2]); break;
00210     default: assert(false); return;
00211   }
00212 
00213 #ifndef NDEBUG
00214   halfspaceD3<PT,PD> h(x.pi[2],x.pi[1],x.pi[0]);
00215   assert( h.isInside(pi[i]) );
00216 #endif
00217 }

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

Calculate the altitude to point on a triangle face.

Definition at line 439 of file tetrahedron.h.

References d2matsolve(), crossproduct::eval(), and tetrahedron< PT, PD >::pi.

00440 {
00441   PT a,b,c;
00442 
00443   switch(i)
00444   {
00445     case 0:
00446       a=pi[1]; b=pi[2]; c=pi[3];
00447       break;
00448 
00449     case 1:
00450       a=pi[0]; b=pi[2]; c=pi[3];
00451       break;
00452 
00453     case 2:
00454       a=pi[0]; b=pi[1]; c=pi[3];
00455 //cout << SHOW(a) << endl;
00456 //cout << SHOW(b) << endl;
00457 //cout << SHOW(c) << endl;
00458       break;
00459 
00460     case 3:
00461       a=pi[0]; b=pi[1]; c=pi[2];
00462       break;
00463    
00464     default:
00465       assert(false);
00466   }
00467 
00468   PT ab = b - a;
00469   PT ac = c - a;
00470 
00471 //cout << SHOW(ab) << endl;
00472 //cout << SHOW(ac) << endl;
00473 
00474   PT w;
00475   crossproduct::eval(w,ab,ac);
00476   //crossprod< T > cross;
00477   //cross(w,ab,ac);
00478 
00479   PT act;
00480   PT abt;
00481   crossproduct::eval(act,w,ac);
00482   crossproduct::eval(abt,w,ab);
00483   //cross(act,w,ac);
00484   //cross(abt,w,ab);
00485 
00486   PT t0, t1;
00487 
00488   // Usually only one solving is necessary.
00489   // However if the determinant is zero, try
00490   // all the other combinations, one should be ok.
00491 
00492   // Assuming that the object is a tetrahedron: all the 
00493   // four points are unique.
00494 
00495   bool test = 
00496   d2matsolve
00497   (
00498     t0, t1,
00499     abt.x, -act.x,
00500     abt.y, -act.y,
00501     b.x - c.x,
00502     b.y - c.y
00503   );
00504 
00505   if (!test)
00506   {
00507     test = 
00508     d2matsolve
00509     (
00510       t0, t1,
00511       abt.x, -act.x,
00512        abt.z, -act.z,
00513       b.x - c.x,
00514       b.z - c.z
00515     );
00516   }
00517 
00518   if (!test)
00519   {
00520     test = 
00521     d2matsolve
00522     (
00523       t0, t1,
00524       abt.y, -act.y,
00525        abt.z, -act.z,
00526       b.y - c.y,
00527       b.z - c.z
00528     );
00529   }
00530 
00531   x = c + abt * t0;
00532 }

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

If the point representation is invalid and NDEBUG is not definded the function asserts.

Definition at line 230 of file tetrahedron.h.

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

00231 {
00232   PT a0(pi[1]-pi[0]);
00233   PT a1(pi[2]-pi[0]);
00234   PT a2;
00235   crossproduct::evalxyz(a2,a1,a0);
00236 
00237   PT q(pi[3]-pi[0]);
00238   bool res = (q.x*a2.x+q.y*a2.y+q.z*a2.z>0);
00239 
00240   return res;
00241 }

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

Definition at line 386 of file tetrahedron.h.

References crossproduct::eval(), and tetrahedron< PT, PD >::pi.

Referenced by visualize_tetrahedron< T >::eval().

00387 {
00388   PT a,b,c,d;
00389 
00390   // Let d be the opposite point.
00391   // Choose a as vector vertex.
00392 
00393   switch(i)
00394   {
00395     case 0:
00396       a=pi[3]; b=pi[2]; c=pi[1]; d=pi[0];
00397       break;
00398 
00399     case 1:
00400       a=pi[0]; b=pi[2]; c=pi[3]; d=pi[1];
00401       break;
00402 
00403     case 2:
00404       a=pi[0]; b=pi[1]; c=pi[3]; d=pi[2];
00405 //cout << SHOW(a) << endl;
00406 //cout << SHOW(b) << endl;
00407 //cout << SHOW(c) << endl;
00408       break;
00409 
00410     case 3:
00411       a=pi[0]; b=pi[1]; c=pi[2]; d=pi[3];
00412       break;
00413    
00414     default:
00415       assert(false);
00416   }
00417 
00418   // ab
00419   PT A(b-a);
00420   // ac
00421   PT B(c-a);
00422 
00423   PT N;
00424   crossproduct::eval(N,A,B);
00425   //crossprod< T >()(N,A,B);
00426   assert(N.dot()!=0.0);
00427   
00428   x = N*( N.dot(a-d) / N.dot() )+ d;
00429 }


Member Data Documentation

template<typename PT, typename PD>
PT tetrahedron< PT, PD >::pi[4]


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

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