GEL
2
GEL is a library for Geometry and Linear Algebra
|
00001 #ifndef __GEOMETRY_TRIANGLE_H 00002 #define __GEOMETRY_TRIANGLE_H 00003 00004 #include "CGLA/Vec2f.h" 00005 #include "CGLA/Vec3f.h" 00006 #include "CGLA/Mat3x3f.h" 00007 00008 #define COMPUTE_SIGN 00009 00010 namespace Geometry 00011 { 00012 00013 class Triangle 00014 { 00015 CGLA::Vec3f vert[3]; 00016 CGLA::Vec3f edge[3]; 00017 00018 #ifdef COMPUTE_SIGN 00019 CGLA::Vec3f vert_norm[3]; 00020 CGLA::Vec3f edge_norm[3]; 00021 #endif 00022 CGLA::Vec3f face_norm; 00023 00024 CGLA::Vec3f tri_plane_edge_norm[3]; 00025 float edge_len[3]; 00026 00027 public: 00028 00029 Triangle() {} 00030 00031 Triangle(const CGLA::Vec3f& _v0, 00032 const CGLA::Vec3f& _v1, 00033 const CGLA::Vec3f& _v2, 00034 00035 const CGLA::Vec3f& _vn0, 00036 const CGLA::Vec3f& _vn1, 00037 const CGLA::Vec3f& _vn2, 00038 00039 const CGLA::Vec3f& _en0, 00040 const CGLA::Vec3f& _en1, 00041 const CGLA::Vec3f& _en2); 00042 00043 bool intersect(const CGLA::Vec3f&, const CGLA::Vec3f&, float&) const; 00044 00045 const CGLA::Vec3f get_pmin() const 00046 { 00047 return v_min(vert[0],v_min(vert[1],vert[2])); 00048 } 00049 00050 const CGLA::Vec3f get_pmax() const 00051 { 00052 return v_max(vert[0],v_max(vert[1],vert[2])); 00053 } 00054 00055 const CGLA::Vec3f centre() const 00056 { 00057 return (vert[0]+vert[1]+vert[2])/3.0f; 00058 } 00059 00060 const float area() const 00061 { 00062 return 0.5 * (cross(edge[0],-edge[2])).length(); 00063 } 00064 00065 const CGLA::Vec3f get_centre() const 00066 { 00067 CGLA::Vec3f pmin = get_pmin(); 00068 CGLA::Vec3f pmax = get_pmax(); 00069 return (pmax-pmin)/2.0f+pmin; 00070 } 00071 00072 bool signed_distance(const CGLA::Vec3f& p, float& sq_dist, float& sgn) const; 00073 00074 CGLA::Vec3f get_v0() const {return vert[0];} 00075 CGLA::Vec3f get_v1() const {return vert[1];} 00076 CGLA::Vec3f get_v2() const {return vert[2];} 00077 00078 const CGLA::Vec3f& get_edge(int i) const {return edge[i];} 00079 00080 const CGLA::Vec3f& get_face_norm() const {return face_norm;} 00081 00082 }; 00083 00084 } 00085 #endif