Home
Downloads
Documentation
Installation
User Guide
man-pages
API Documentation
README
Release Notes
Changes
License
Support
SourceForge Project
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
src
OpenFOAM
meshes
primitiveShapes
triangle
triangle.H
Go to the documentation of this file.
1
/*---------------------------------------------------------------------------*\
2
========= |
3
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4
\\ / O peration |
5
\\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6
\\/ M anipulation |
7
-------------------------------------------------------------------------------
8
License
9
This file is part of OpenFOAM.
10
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.
15
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
19
for more details.
20
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/>.
23
24
Class
25
Foam::triangle
26
27
Description
28
A triangle primitive used to calculate face normals and swept volumes.
29
30
SourceFiles
31
triangleI.H
32
33
\*---------------------------------------------------------------------------*/
34
35
#ifndef triangle_H
36
#define triangle_H
37
38
#include "
intersection.H
"
39
#include <
OpenFOAM/vector.H
>
40
#include <
OpenFOAM/pointHit.H
>
41
42
43
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44
45
namespace
Foam
46
{
47
48
class
Istream;
49
class
Ostream;
50
51
// Forward declaration of friend functions and operators
52
53
template
<
class
Po
int
,
class
Po
int
Ref>
class
triangle;
54
55
template
<
class
Po
int
,
class
Po
int
Ref>
56
inline
Istream&
operator
>>
57
(
58
Istream&,
59
triangle<Point, PointRef>&
60
);
61
62
template
<
class
Po
int
,
class
Po
int
Ref>
63
inline
Ostream&
operator
<<
64
(
65
Ostream&,
66
const
triangle<Point, PointRef>&
67
);
68
69
70
/*---------------------------------------------------------------------------*\
71
class triangle Declaration
72
\*---------------------------------------------------------------------------*/
73
74
template
<
class
Po
int
,
class
Po
int
Ref>
75
class
triangle
76
{
77
// Private data
78
79
PointRef a_, b_, c_;
80
81
// Private member functions
82
83
//- Fast distance to triangle calculation. From
84
// "Distance Between Point and Trangle in 3D"
85
// David Eberly, Magic Software Inc. Aug. 2002.
86
// Works on function Q giving distance to point and tries to
87
// minimize this.
88
static
pointHit
nearestPoint
89
(
90
const
Point& baseVertex,
91
const
vector
& E0,
92
const
vector
& E1,
93
const
point
& P
94
);
95
96
97
public
:
98
99
//- Return types for classify
100
enum
proxType
101
{
102
NONE
,
103
POINT
,
// Close to point
104
EDGE
// Close to edge
105
};
106
107
108
// Constructors
109
110
//- Construct from three points
111
inline
triangle
(
const
Point&
a
,
const
Point&
b
,
const
Point&
c
);
112
113
//- Construct from Istream
114
inline
triangle
(
Istream
&);
115
116
117
// Member Functions
118
119
// Access
120
121
//- Return first vertex
122
inline
const
Point&
a
()
const
;
123
124
//- Return second vertex
125
inline
const
Point&
b
()
const
;
126
127
//- Return third vertex
128
inline
const
Point&
c
()
const
;
129
130
131
// Properties
132
133
//- Return centre (centroid)
134
inline
Point
centre
()
const
;
135
136
//- Return scalar magnitude
137
inline
scalar
mag
()
const
;
138
139
//- Return vector normal
140
inline
vector
normal
()
const
;
141
142
//- Return circum-centre
143
inline
vector
circumCentre
()
const
;
144
145
//- Return circum-radius
146
inline
scalar
circumRadius
()
const
;
147
148
//- Return quality: Ratio triangle and circum-circle area
149
inline
scalar
quality
()
const
;
150
151
//- Return swept-volume
152
inline
scalar
sweptVol
(
const
triangle
& t)
const
;
153
154
//- Return point intersection with a ray.
155
// For a hit, the distance is signed. Positive number
156
// represents the point in front of triangle.
157
// In case of miss pointHit is set to nearest point
158
// on triangle and its distance to the distance between
159
// the original point and the plane intersection point
160
inline
pointHit
ray
161
(
162
const
point
&
p
,
163
const
vector
& q,
164
const
intersection::algorithm
=
intersection::FULL_RAY
,
165
const
intersection::direction
dir =
intersection::VECTOR
166
)
const
;
167
168
//- Fast intersection with a ray.
169
// For a hit, the pointHit.distance() is the line parameter t :
170
// intersection=p+t*q. Only defined for VISIBLE, FULL_RAY or
171
// HALF_RAY. tol increases the virtual size of the triangle
172
// by a relative factor.
173
inline
pointHit
intersection
174
(
175
const
point
&
p
,
176
const
vector
& q,
177
const
intersection::algorithm
alg,
178
const
scalar tol = 0.0
179
)
const
;
180
181
//- Return nearest point to p on triangle
182
inline
pointHit
nearestPoint
183
(
184
const
point
&
p
185
)
const
;
186
187
//- Classify point in triangle plane w.r.t. triangle edges.
188
// - inside (true returned)/outside (false returned)
189
// - near point (nearType=POINT, nearLabel=0, 1, 2)
190
// - near edge (nearType=EDGE, nearLabel=0, 1, 2)
191
// Note: edges are counted from starting
192
// vertex so e.g. edge 2 is from f[2] to f[0]
193
// tol is fraction to account for truncation error. Is only used
194
// when comparing normalized (0..1) numbers.
195
bool
classify
196
(
197
const
point
&
p
,
198
const
scalar tol,
199
label& nearType,
200
label& nearLabel
201
)
const
;
202
203
204
// IOstream operators
205
206
friend
Istream
&
operator
>> <Point, PointRef>
207
(
208
Istream
&,
209
triangle
&
210
);
211
212
friend
Ostream
& operator<< <Point, PointRef>
213
(
214
Ostream
&,
215
const
triangle
&
216
);
217
};
218
219
220
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
221
222
}
// End namespace Foam
223
224
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
225
226
#include "
triangleI.H
"
227
228
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
229
230
#endif
231
232
// ************************ vim: set sw=4 sts=4 et: ************************ //