1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software; you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 A triangle primitive used to calculate face normals and swept volumes.
34 \*---------------------------------------------------------------------------*/
39 #include "intersection.H"
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
52 // Forward declaration of friend functions and operators
54 template<class Point, class PointRef> class triangle;
56 template<class Point, class PointRef>
57 inline Istream& operator>>
60 triangle<Point, PointRef>&
63 template<class Point, class PointRef>
64 inline Ostream& operator<<
67 const triangle<Point, PointRef>&
71 /*---------------------------------------------------------------------------*\
72 class triangle Declaration
73 \*---------------------------------------------------------------------------*/
75 template<class Point, class PointRef>
82 // Private member functions
84 //- Fast distance to triangle calculation. From
85 // "Distance Between Point and Trangle in 3D"
86 // David Eberly, Magic Software Inc. Aug. 2002.
87 // Works on function Q giving distance to point and tries to
89 static pointHit nearestPoint
91 const Point& baseVertex,
100 //- Return types for classify
104 POINT, // Close to point
105 EDGE // Close to edge
111 //- Construct from three points
112 inline triangle(const Point& a, const Point& b, const Point& c);
114 //- Construct from Istream
115 inline triangle(Istream&);
122 //- Return first vertex
123 inline const Point& a() const;
125 //- Return second vertex
126 inline const Point& b() const;
128 //- Return third vertex
129 inline const Point& c() const;
134 //- Return centre (centroid)
135 inline Point centre() const;
137 //- Return scalar magnitude
138 inline scalar mag() const;
140 //- Return vector normal
141 inline vector normal() const;
143 //- Return circum-centre
144 inline vector circumCentre() const;
146 //- Return circum-radius
147 inline scalar circumRadius() const;
149 //- Return quality: Ratio triangle and circum-circle area
150 inline scalar quality() const;
152 //- Return swept-volume
153 inline scalar sweptVol(const triangle& t) const;
155 //- Return point intersection with a ray.
156 // For a hit, the distance is signed. Positive number
157 // represents the point in front of triangle.
158 // In case of miss pointHit is set to nearest point
159 // on triangle and its distance to the distance between
160 // the original point and the plane intersection point
165 const intersection::algorithm = intersection::FULL_RAY,
166 const intersection::direction dir = intersection::VECTOR
169 //- Fast intersection with a ray.
170 // For a hit, the pointHit.distance() is the line parameter t :
171 // intersection=p+t*q. Only defined for VISIBLE, FULL_RAY or
172 // HALF_RAY. tol increases the virtual size of the triangle
173 // by a relative factor.
174 inline pointHit intersection
178 const intersection::algorithm alg,
179 const scalar tol = 0.0
182 //- Return nearest point to p on triangle
183 inline pointHit nearestPoint
188 //- Classify point in triangle plane w.r.t. triangle edges.
189 // - inside (true returned)/outside (false returned)
190 // - near point (nearType=POINT, nearLabel=0, 1, 2)
191 // - near edge (nearType=EDGE, nearLabel=0, 1, 2)
192 // Note: edges are counted from starting
193 // vertex so e.g. edge 2 is from f[2] to f[0]
194 // tol is fraction to account for truncation error. Is only used
195 // when comparing normalized (0..1) numbers.
205 // IOstream operators
207 friend Istream& operator>> <Point, PointRef>
213 friend Ostream& operator<< <Point, PointRef>
221 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
223 } // End namespace Foam
225 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
227 #include "triangleI.H"
229 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
233 // ************************************************************************* //