1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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, see <http://www.gnu.org/licenses/>.
28 A triangle primitive used to calculate face normals and swept volumes.
33 \*---------------------------------------------------------------------------*/
38 #include "intersection.H"
43 #include "FixedList.H"
46 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
54 // Forward declaration of friend functions and operators
56 template<class Point, class PointRef> class triangle;
58 template<class Point, class PointRef>
59 inline Istream& operator>>
62 triangle<Point, PointRef>&
65 template<class Point, class PointRef>
66 inline Ostream& operator<<
69 const triangle<Point, PointRef>&
73 /*---------------------------------------------------------------------------*\
74 Class triangle Declaration
75 \*---------------------------------------------------------------------------*/
77 template<class Point, class PointRef>
87 //- Return types for classify
91 POINT, // Close to point
98 //- Construct from three points
99 inline triangle(const Point& a, const Point& b, const Point& c);
101 //- Construct from three points in the list of points
102 // The indices could be from triFace etc.
106 const FixedList<label, 3>& indices
109 //- Construct from Istream
110 inline triangle(Istream&);
117 //- Return first vertex
118 inline const Point& a() const;
120 //- Return second vertex
121 inline const Point& b() const;
123 //- Return third vertex
124 inline const Point& c() const;
129 //- Return centre (centroid)
130 inline Point centre() const;
132 //- Return scalar magnitude
133 inline scalar mag() const;
135 //- Return vector normal
136 inline vector normal() const;
138 //- Return circum-centre
139 inline Point circumCentre() const;
141 //- Return circum-radius
142 inline scalar circumRadius() const;
144 //- Return quality: Ratio of triangle and circum-circle
145 // area, scaled so that an equilateral triangle has a
147 inline scalar quality() const;
149 //- Return swept-volume
150 inline scalar sweptVol(const triangle& t) const;
152 //- Return the inertia tensor, with optional reference
153 // point and density specification
154 inline tensor inertia
156 PointRef refPt = vector::zero,
160 //- Return a random point on the triangle from a uniform
162 inline Point randomPoint(Random& rndGen) const;
164 //- Calculate the barycentric coordinates of the given
165 // point, in the same order as a, b, c. Returns the
166 // determinant of the solution.
167 inline scalar barycentric
173 //- Return point intersection with a ray.
174 // For a hit, the distance is signed. Positive number
175 // represents the point in front of triangle.
176 // In case of miss pointHit is set to nearest point
177 // on triangle and its distance to the distance between
178 // the original point and the plane intersection point
183 const intersection::algorithm = intersection::FULL_RAY,
184 const intersection::direction dir = intersection::VECTOR
187 //- Fast intersection with a ray.
188 // For a hit, the pointHit.distance() is the line parameter t :
189 // intersection=p+t*q. Only defined for VISIBLE, FULL_RAY or
190 // HALF_RAY. tol increases the virtual size of the triangle
191 // by a relative factor.
192 inline pointHit intersection
196 const intersection::algorithm alg,
197 const scalar tol = 0.0
200 //- Find the nearest point to p on the triangle and classify it:
201 // + near point (nearType=POINT, nearLabel=0, 1, 2)
202 // + near edge (nearType=EDGE, nearLabel=0, 1, 2)
203 // Note: edges are counted from starting
204 // vertex so e.g. edge 2 is from f[2] to f[0]
205 pointHit nearestPointClassify
212 //- Return nearest point to p on triangle
213 inline pointHit nearestPoint(const point& p) const;
215 //- Classify nearest point to p in triangle plane
216 // w.r.t. triangle edges and points. Returns inside
217 // (true)/outside (false).
226 // IOstream operators
228 friend Istream& operator>> <Point, PointRef>
234 friend Ostream& operator<< <Point, PointRef>
242 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
244 } // End namespace Foam
246 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
248 #include "triangleI.H"
250 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
254 // ************************************************************************* //