00001
00006 #ifndef TRIANGLE_H
00007 #define TRIANGLE_H
00008
00009
00010
00011
00012
00013
00014 #include <vector>
00015 #include "geom.h"
00016 #include "ray.h"
00017 #include "lang.h"
00018
00019
00020
00021
00022
00023
00024
00025 typedef vector<Triangle *>TriangleArray;
00026
00028
00034 class Triangle : Polygon {
00035
00036 private :
00037
00038
00039 public:
00040
00042 Triangle();
00043
00045 Triangle (const Vector3 &v0,const Vector3 &v1,const Vector3 &v2);
00046
00048 static Polygon decode(Pval *plist);
00049
00051 virtual Vector4 plane();
00052
00054 virtual Real area();
00055
00056
00057 };
00058
00059 ofstream & operator<<(ofstream &out,const Triangle &tri);
00060 ifstream & operator>>(ifstream &in,const Triangle &tri);
00061
00062 inline
00063 Triangle::Triangle()
00064 : Polygon(3)
00065 {
00066 }
00067
00068
00069 inline
00070 Triangle::Triangle(const Vector3 &v0,const Vector3 &v1,const Vector3 &v2)
00071 : Polygon(3)
00072 {
00073 vertices(0) = v0;
00074 vertices(1) = v1;
00075 vertices(2) = v2;
00076 }
00077
00078 inline Vector4
00079 Triangle::plane()
00080 {
00081 Vector3 n = normal();
00082 Real d = -(n*vertices[0]);
00083 return Vector4(n(0), n(1), n(2), d);
00084 }
00085
00086 inline Real
00087 Triangle::area()
00088 {
00089 return (vertices(1) - vertices(0)).cross(vertices(2) - vertices(0)).norm()/2;
00090 }
00091
00092
00093 #endif //TRIANGLE_H