Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #ifndef __SP_DIMENSION_QUADRANGLE3D_H__
00009 #define __SP_DIMENSION_QUADRANGLE3D_H__
00010
00011
00012 #include "Base/spStandard.hpp"
00013 #include "Base/spDimensionVector3D.hpp"
00014
00015
00016 namespace sp
00017 {
00018 namespace dim
00019 {
00020
00021
00023 template <typename T> class quadrangle3d
00024 {
00025
00026 public:
00027
00028 quadrangle3d()
00029 {
00030 }
00031 quadrangle3d(const vector3d<T> &A, const vector3d<T> &B, const vector3d<T> &C, const vector3d<T> &D) :
00032 PointA(A),
00033 PointB(B),
00034 PointC(C),
00035 PointD(D)
00036 {
00037 }
00038 quadrangle3d(const quadrangle3d<T> &Other) :
00039 PointA(Other.PointA),
00040 PointB(Other.PointB),
00041 PointC(Other.PointC),
00042 PointD(Other.PointD)
00043 {
00044 }
00045 ~quadrangle3d()
00046 {
00047 }
00048
00049
00050
00051 inline void operator = (const quadrangle3d<T> &Other)
00052 {
00053 PointA = Other.PointA;
00054 PointB = Other.PointB;
00055 PointC = Other.PointC;
00056 PointD = Other.PointD;
00057 }
00058
00059
00060
00061 inline const vector3d<T> operator [] (s32 i) const
00062 {
00063 switch (i)
00064 {
00065 case 0: return PointA;
00066 case 1: return PointB;
00067 case 2: return PointC;
00068 case 3: return PointD;
00069 }
00070 return vector3d<T>();
00071 }
00072
00073 inline vector3d<T>& operator [] (s32 i)
00074 {
00075 return *(&PointA + i);
00076 }
00077
00078
00079
00080 inline vector3d<T> getNormal() const
00081 {
00082 return dim::vector3d<T>( (PointB - PointA).cross(PointC - PointA) ).normalize();
00083 }
00084
00085 inline vector3d<T> getCenter() const
00086 {
00087 return (PointA + PointB + PointC + PointD) / 4;
00088 }
00089
00090 inline T getArea() const
00091 {
00092 return dim::vector3d<T>( (PointB - PointA).cross(PointC - PointA) ).getLength();
00093 }
00094
00096 inline bool isPointInside(const vector3d<T> &Vector) const
00097 {
00098 return
00099 ( vector3d<T>::isPointOnSameSide(Vector, PointA, PointB, PointC) &&
00100 vector3d<T>::isPointOnSameSide(Vector, PointB, PointA, PointC) &&
00101 vector3d<T>::isPointOnSameSide(Vector, PointC, PointA, PointB) ) ||
00102 ( vector3d<T>::isPointOnSameSide(Vector, PointA, PointC, PointD) &&
00103 vector3d<T>::isPointOnSameSide(Vector, PointC, PointA, PointD) &&
00104 vector3d<T>::isPointOnSameSide(Vector, PointD, PointA, PointC) );
00105 }
00106
00107 inline quadrangle3d<T> getSwaped() const
00108 {
00109 return quadrangle3d<T>(PointA, PointD, PointC, PointB);
00110 }
00111 inline quadrangle3d<T>& swap()
00112 {
00113 math::Swap(PointB, PointD);
00114 return *this;
00115 }
00116
00117 inline bool equal(const quadrangle3d<T> &other, f32 Precision = math::ROUNDING_ERROR) const
00118 {
00119 return
00120 PointA.equal(other.PointA, Precision) &&
00121 PointB.equal(other.PointB, Precision) &&
00122 PointC.equal(other.PointC, Precision) &&
00123 PointD.equal(other.PointC, Precision);
00124 }
00125 inline bool empty() const
00126 {
00127 return PointA.empty() && PointB.empty() && PointC.empty() && PointD.empty();
00128 }
00129
00130 template <typename B> inline quadrangle3d<B> cast() const
00131 {
00132 return triangle3d<B>(
00133 PointA.cast<B>(), PointB.cast<B>(), PointC.cast<B>(), PointD.cast<B>()
00134 );
00135 }
00136
00137
00138
00139 vector3d<T> PointA, PointB, PointC, PointD;
00140
00141 };
00142
00143 typedef quadrangle3d<s32> quadrangle3di;
00144 typedef quadrangle3d<f32> quadrangle3df;
00145
00146
00147 }
00148
00149 }
00150
00151
00152 #endif
00153
00154
00155
00156