00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "triangle.H"
00030 #include "IOstreams.H"
00031
00032
00033
00034 namespace Foam
00035 {
00036
00037
00038
00039 template<class Point, class PointRef>
00040 inline tetrahedron<Point, PointRef>::tetrahedron
00041 (
00042 const Point& a,
00043 const Point& b,
00044 const Point& c,
00045 const Point& d
00046 )
00047 :
00048 a_(a),
00049 b_(b),
00050 c_(c),
00051 d_(d)
00052 {}
00053
00054
00055 template<class Point, class PointRef>
00056 inline tetrahedron<Point, PointRef>::tetrahedron(Istream& is)
00057 {
00058
00059 is.readBegin("tetrahedron");
00060
00061 is >> a_ >> b_ >> c_ >> d_;
00062
00063
00064 is.readEnd("tetrahedron");
00065
00066
00067 is.check("tetrahedron::tetrahedron(Istream& is)");
00068 }
00069
00070
00071
00072
00073 template<class Point, class PointRef>
00074 inline const Point& tetrahedron<Point, PointRef>::a() const
00075 {
00076 return a_;
00077 }
00078
00079
00080 template<class Point, class PointRef>
00081 inline const Point& tetrahedron<Point, PointRef>::b() const
00082 {
00083 return b_;
00084 }
00085
00086
00087 template<class Point, class PointRef>
00088 inline const Point& tetrahedron<Point, PointRef>::c() const
00089 {
00090 return c_;
00091 }
00092
00093
00094 template<class Point, class PointRef>
00095 inline const Point& tetrahedron<Point, PointRef>::d() const
00096 {
00097 return d_;
00098 }
00099
00100
00101 template<class Point, class PointRef>
00102 inline vector tetrahedron<Point, PointRef>::Sa() const
00103 {
00104 return triangle<Point, PointRef>(b_, c_, d_).normal();
00105 }
00106
00107
00108 template<class Point, class PointRef>
00109 inline vector tetrahedron<Point, PointRef>::Sb() const
00110 {
00111 return triangle<Point, PointRef>(a_, d_, c_).normal();
00112 }
00113
00114
00115 template<class Point, class PointRef>
00116 inline vector tetrahedron<Point, PointRef>::Sc() const
00117 {
00118 return triangle<Point, PointRef>(a_, b_, d_).normal();
00119 }
00120
00121
00122 template<class Point, class PointRef>
00123 inline vector tetrahedron<Point, PointRef>::Sd() const
00124 {
00125 return triangle<Point, PointRef>(a_, c_, b_).normal();
00126 }
00127
00128
00129 template<class Point, class PointRef>
00130 inline scalar tetrahedron<Point, PointRef>::mag() const
00131 {
00132 return (1.0/6.0)*(((b_ - a_) ^ (c_ - a_)) & (d_ - a_));
00133 }
00134
00135
00136 template<class Point, class PointRef>
00137 inline vector tetrahedron<Point, PointRef>::circumCentre() const
00138 {
00139 vector a = b_ - a_;
00140 vector b = c_ - a_;
00141 vector c = d_ - a_;
00142
00143 scalar lamda = magSqr(c) - (a&c);
00144 scalar mu = magSqr(b) - (a&b);
00145
00146 vector ba = b^a;
00147 vector ca = c^a;
00148
00149 return a_ + 0.5*(a + (lamda*ba - mu*ca)/(c&ba));
00150 }
00151
00152
00153 template<class Point, class PointRef>
00154 inline scalar tetrahedron<Point, PointRef>::circumRadius() const
00155 {
00156 return Foam::mag(a_ - circumCentre());
00157 }
00158
00159
00160
00161
00162 template<class point, class pointRef>
00163 inline Istream& operator>>(Istream& is, tetrahedron<point, pointRef>& t)
00164 {
00165
00166 is.readBegin("tetrahedron");
00167
00168 is >> t.a_ >> t.b_ >> t.c_ >> t.d_;
00169
00170
00171 is.readEnd("tetrahedron");
00172
00173
00174 is.check("Istream& operator>>(Istream&, tetrahedron&)");
00175
00176 return is;
00177 }
00178
00179
00180 template<class Point, class PointRef>
00181 inline Ostream& operator<<(Ostream& os, const tetrahedron<Point, PointRef>& t)
00182 {
00183 os << nl
00184 << token::BEGIN_LIST
00185 << t.a_ << token::SPACE << t.b_
00186 << token::SPACE << t.c_ << token::SPACE << t.d_
00187 << token::END_LIST;
00188
00189 return os;
00190 }
00191
00192
00193
00194
00195 }
00196
00197