OpenLB 1.8.1
Loading...
Searching...
No Matches
olb::STLtriangle< T > Struct Template Reference

#include <stlReader.h>

+ Collaboration diagram for olb::STLtriangle< T >:

Public Member Functions

bool testRayIntersect (const Vector< T, 3 > &pt, const Vector< T, 3 > &dir, Vector< T, 3 > &q, T &alpha, const T &rad=T(), bool print=false)
 Test intersection between ray and triangle.
 
Vector< T, 3 > closestPtPointTriangle (const Vector< T, 3 > &pt) const
 computes closest Point in a triangle to another point.
 
 STLtriangle ()
 Constructor constructs.
 
 STLtriangle (STLtriangle< T > const &tri)
 CopyConstructor copies.
 
STLtriangle< T > & operator= (STLtriangle< T > const &tri)
 Operator= equals.
 
 ~STLtriangle ()
 
void init ()
 Initializes triangle and precomputes member variables.
 
Vector< T, 3 > & getNormal ()
 Return write access to normal.
 
const Vector< T, 3 > & getNormal () const
 Return read access to normal.
 
Vector< T, 3 > getCenter ()
 Returns center.
 
std::vector< T > getE0 ()
 Returns Pt0-Pt1.
 
std::vector< T > getE1 ()
 Returns Pt0-Pt2.
 
bool isPointInside (const PhysR< T, 3 > &pt) const
 Check whether a point is inside a triangle.
 
bool getPointToEdgeDistances (const Vector< T, 3 > &input, Vector< T, 3 > &output, T sensitivity=1.e-15)
 Returns true if the point is on a edge (smaller than sensitivity) and gives the perpendicular distances to the edges in output https://www.math.kit.edu/ianm2/lehre/am22016s/media/distance-harvard.pdf.
 
bool isEdgePoint (const Vector< T, 3 > &input, Vector< T, 3 > &P1, Vector< T, 3 > &P2, T sensitivity=1.e-15)
 Returns true if is near edge (smaller than sensitivity) and not near vortex and saves in P1 and P2 the vortex points of the edge.
 
bool isVortexPoint (const Vector< T, 3 > &input, Vector< T, 3 > &P, T sensitivity=1.e-15)
 Returns true if is near vortex (smaller than sensitivity) and saves in P the vortex points.
 
Vector< T, 3 > closestPointTo (Vector< T, 3 > physR)
 Returns the closest point to physR on the triangle.
 
bool testRayIntersect (const Vector< T, 3 > &pt, const Vector< T, 3 > &dir, Vector< T, 3 > &q, T &alpha, const T &rad=T(), bool print=false)
 Test intersection between ray and triangle.
 
Vector< T, 3 > closestPtPointTriangle (const Vector< T, 3 > &pt) const
 
 STLtriangle ()
 Constructor constructs.
 
 STLtriangle (STLtriangle< T > const &tri)
 CopyConstructor copies.
 
STLtriangle< T > & operator= (STLtriangle< T > const &tri)
 Operator= equals.
 
 ~STLtriangle ()
 
void init ()
 Initializes triangle and precomputes member variables.
 
Vector< T, 3 > & getNormal ()
 Return write access to normal.
 
const Vector< T, 3 > & getNormal () const
 Return read access to normal.
 
Vector< T, 3 > getCenter ()
 Returns center.
 
std::vector< T > getE0 ()
 Returns Pt0-Pt1.
 
std::vector< T > getE1 ()
 Returns Pt0-Pt2.
 
bool isPointInside (const PhysR< T, 3 > &pt) const
 Check whether a point is inside a triangle.
 
bool getPointToEdgeDistances (const Vector< T, 3 > &input, Vector< T, 3 > &output, T sensitivity=1.e-15)
 Returns true if the point is on a edge (smaller than sensitivity) and gives the perpendicular distances to the edges in output https://www.math.kit.edu/ianm2/lehre/am22016s/media/distance-harvard.pdf.
 
bool isEdgePoint (const Vector< T, 3 > &input, Vector< T, 3 > &P1, Vector< T, 3 > &P2, T sensitivity=1.e-15)
 Returns true if is near edge (smaller than sensitivity) and not near vortex and saves in P1 and P2 the vortex points of the edge.
 
bool isVortexPoint (const Vector< T, 3 > &input, Vector< T, 3 > &P, T sensitivity=1.e-15)
 Returns true if is near vortex (smaller than sensitivity) and saves in P the vortex points.
 

Public Attributes

std::vector< Vector< T, 3 > > point
 A triangle contains 3 Points.
 
Vector< T, 3 > normal
 normal of triangle
 
Vector< T, 3 > uBeta
 variables explained in http://www.uninformativ.de/bin/RaytracingSchnitttests-76a577a-CC-BY.pdf page 7-12 precomputed for speedup
 
Vector< T, 3 > uGamma
 
T d
 
T kBeta
 
T kGamma
 
std::vector< Vertex< T, 3 > > point
 A triangle contains 3 Points.
 

Detailed Description

template<typename T>
struct olb::STLtriangle< T >

Definition at line 79 of file STLreaderForSubgridParticleWallContact.h.

Constructor & Destructor Documentation

◆ STLtriangle() [1/4]

template<typename T >
olb::STLtriangle< T >::STLtriangle ( )
inline

Constructor constructs.

Definition at line 79 of file stlReader.h.

79:point(3, Vector<T,3>()), normal(T()), uBeta(T()), uGamma(T()), d(T()), kBeta(T()), kGamma(T()) {};
Vector< T, 3 > uBeta
variables explained in http://www.uninformativ.de/bin/RaytracingSchnitttests-76a577a-CC-BY....
Definition stlReader.h:74
Vector< T, 3 > normal
normal of triangle
Definition stlReader.h:70
Vector< T, 3 > uGamma
Definition stlReader.h:74
std::vector< Vector< T, 3 > > point
A triangle contains 3 Points.
Definition stlReader.h:67

◆ STLtriangle() [2/4]

template<typename T >
olb::STLtriangle< T >::STLtriangle ( STLtriangle< T > const & tri)
inline

CopyConstructor copies.

Definition at line 81 of file stlReader.h.

81:point(tri.point), normal(tri.normal), uBeta(tri.uBeta), uGamma(tri.uGamma), d(tri.d), kBeta(tri.kBeta), kGamma(tri.kGamma) {};

◆ ~STLtriangle() [1/2]

template<typename T >
olb::STLtriangle< T >::~STLtriangle ( )
inline

Definition at line 95 of file stlReader.h.

95{};

◆ STLtriangle() [3/4]

template<typename T >
olb::STLtriangle< T >::STLtriangle ( )
inline

Constructor constructs.

Definition at line 104 of file STLreaderForSubgridParticleWallContact.h.

104:point(3, Vertex<T,3>()), normal(T()), uBeta(T()), uGamma(T()), d(T()), kBeta(T()), kGamma(T()) {};

◆ STLtriangle() [4/4]

template<typename T >
olb::STLtriangle< T >::STLtriangle ( STLtriangle< T > const & tri)
inline

CopyConstructor copies.

Definition at line 106 of file STLreaderForSubgridParticleWallContact.h.

106:point(tri.point), normal(tri.normal), uBeta(tri.uBeta), uGamma(tri.uGamma), d(tri.d), kBeta(tri.kBeta), kGamma(tri.kGamma) {};

◆ ~STLtriangle() [2/2]

template<typename T >
olb::STLtriangle< T >::~STLtriangle ( )
inline

Definition at line 120 of file STLreaderForSubgridParticleWallContact.h.

120{};

Member Function Documentation

◆ closestPointTo()

template<typename T >
Vector< T, 3 > olb::STLtriangle< T >::closestPointTo ( Vector< T, 3 > physR)

Returns the closest point to physR on the triangle.

Definition at line 402 of file stlReader.hh.

402 {
403 const auto AB = point[1] - point[0];
404 const auto AC = point[2] - point[0];
405 const auto AP = physR - point[0];
406
407 const auto d1 = AB * AP;
408 const auto d2 = AC * AP;
409 if (d1 <= T{0} && d2 <= T{0}) {
410 return point[0];
411 }
412
413 auto BP = physR - point[1];
414 auto d3 = AB * BP;
415 auto d4 = AC * BP;
416 if (d3 >= T{0} && d4 <= d3) {
417 return point[1];
418 }
419
420 auto vc = d1 * d4 - d3 * d2;
421 if (vc <= T{0} && d1 >= T{0} && d3 <= T{0}) {
422 auto v = d1 / (d1 - d3);
423 return point[0] + v * AB;
424 }
425
426 auto CP = physR - point[2];
427 auto d5 = AB * CP;
428 auto d6 = AC * CP;
429 if (d6 >= T{0} && d5 <= d6) {
430 return point[2];
431 }
432
433 auto vb = d5 * d2 - d1 * d6;
434 if (vb <= T{0} && d2 >= T{0} && d6 <= T{0}) {
435 auto w = d2 / (d2 - d6);
436 return point[0] + w * AC;
437 }
438
439 auto va = d3 * d6 - d5 * d4;
440 if (va <= T{0} && (d4 - d3) >= T{0} && (d5 - d6) >= T{0}) {
441 auto w = (d4 - d3) / ((d4 - d3) + (d5 - d6));
442 return point[1] + w * (point[2] - point[1]);
443 }
444
445 auto denom = 1.0 / (va + vb + vc);
446 auto v = vb * denom;
447 auto w = vc * denom;
448 return point[0] + AB * v + AC * w;
449}

◆ closestPtPointTriangle() [1/2]

template<typename T >
Vector< T, 3 > olb::STLtriangle< T >::closestPtPointTriangle ( const Vector< T, 3 > & pt) const

computes closest Point in a triangle to another point.

source: Real-Time Collision Detection. Christer Ericson. ISBN-10: 1558607323

Definition at line 271 of file stlReader.hh.

273{
274
275 const T nEps = -std::numeric_limits<T>::epsilon();
276 const T Eps = std::numeric_limits<T>::epsilon();
277
278 Vector<T,3> ab = point[1] - point[0];
279 Vector<T,3> ac = point[2] - point[0];
280 Vector<T,3> bc = point[2] - point[1];
281
282 T snom = (pt - point[0])*ab;
283 T sdenom = (pt - point[1])*(point[0] - point[1]);
284
285 T tnom = (pt - point[0])*ac;
286 T tdenom = (pt - point[2])*(point[0] - point[2]);
287
288 if (snom < nEps && tnom < nEps) {
289 return point[0];
290 }
291
292 T unom = (pt - point[1])*bc;
293 T udenom = (pt - point[2])*(point[1] - point[2]);
294
295 if (sdenom < nEps && unom < nEps) {
296 return point[1];
297 }
298 if (tdenom < nEps && udenom < nEps) {
299 return point[2];
300 }
301
302 T vc = normal*crossProduct3D(point[0] - pt, point[1] - pt);
303
304 if (vc < nEps && snom > Eps && sdenom > Eps) {
305 return point[0] + snom / (snom + sdenom) * ab;
306 }
307
308 T va = normal*crossProduct3D(point[1] - pt, point[2] - pt);
309
310 if (va < nEps && unom > Eps && udenom > Eps) {
311 return point[1] + unom / (unom + udenom) * bc;
312 }
313
314 T vb = normal*crossProduct3D(point[2] - pt, point[0] - pt);
315
316 if (vb < nEps && tnom > Eps && tdenom > Eps) {
317 return point[0] + tnom / (tnom + tdenom) * ac;
318 }
319
320 T u = va / (va + vb + vc);
321 T v = vb / (va + vb + vc);
322 T w = 1. - u - v;
323
324 return u * point[0] + v * point[1] + w * point[2];
325}
constexpr Vector< T, 3 > crossProduct3D(const ScalarVector< T, 3, IMPL > &a, const ScalarVector< T, 3, IMPL_ > &b) any_platform
Definition vector.h:263

References olb::crossProduct3D().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ closestPtPointTriangle() [2/2]

template<typename T >
Vector< T, 3 > olb::STLtriangle< T >::closestPtPointTriangle ( const Vector< T, 3 > & pt) const

◆ getCenter() [1/2]

template<typename T >
Vector< T, 3 > olb::STLtriangle< T >::getCenter ( )

Returns center.

Definition at line 101 of file stlReader.hh.

102{
103 Vector<T,3> center( T(0) );
104
105 center[0] = (point[0][0] + point[1][0]
106 + point[2][0]) / 3.;
107 center[1] = (point[0][1] + point[1][1]
108 + point[2][1]) / 3.;
109 center[2] = (point[0][2] + point[1][2]
110 + point[2][2]) / 3.;
111
112 return center;
113}

◆ getCenter() [2/2]

template<typename T >
Vector< T, 3 > olb::STLtriangle< T >::getCenter ( )

Returns center.

◆ getE0() [1/2]

template<typename T >
std::vector< T > olb::STLtriangle< T >::getE0 ( )

Returns Pt0-Pt1.

Definition at line 116 of file stlReader.hh.

117{
118 Vector<T,3> vec;
119 vec[0] = point[0][0] - point[1][0];
120 vec[1] = point[0][1] - point[1][1];
121 vec[2] = point[0][2] - point[1][2];
122 return vec;
123}

◆ getE0() [2/2]

template<typename T >
std::vector< T > olb::STLtriangle< T >::getE0 ( )

Returns Pt0-Pt1.

◆ getE1() [1/2]

template<typename T >
std::vector< T > olb::STLtriangle< T >::getE1 ( )

Returns Pt0-Pt2.

Definition at line 126 of file stlReader.hh.

127{
128 Vector<T,3> vec;
129 vec[0] = point[0][0] - point[2][0];
130 vec[1] = point[0][1] - point[2][1];
131 vec[2] = point[0][2] - point[2][2];
132 return vec;
133}

◆ getE1() [2/2]

template<typename T >
std::vector< T > olb::STLtriangle< T >::getE1 ( )

Returns Pt0-Pt2.

◆ getNormal() [1/4]

template<typename T >
Vector< T, 3 > & olb::STLtriangle< T >::getNormal ( )
inline

Return write access to normal.

Definition at line 100 of file stlReader.h.

101 {
102 return normal;
103 }

References olb::STLtriangle< T >::normal.

+ Here is the caller graph for this function:

◆ getNormal() [2/4]

template<typename T >
Vector< T, 3 > & olb::STLtriangle< T >::getNormal ( )
inline

Return write access to normal.

Definition at line 125 of file STLreaderForSubgridParticleWallContact.h.

126 {
127 return normal;
128 }

References olb::STLtriangle< T >::normal.

◆ getNormal() [3/4]

template<typename T >
const Vector< T, 3 > & olb::STLtriangle< T >::getNormal ( ) const
inline

Return read access to normal.

Definition at line 105 of file stlReader.h.

106 {
107 return normal;
108 }

References olb::STLtriangle< T >::normal.

◆ getNormal() [4/4]

template<typename T >
const Vector< T, 3 > & olb::STLtriangle< T >::getNormal ( ) const
inline

Return read access to normal.

Definition at line 130 of file STLreaderForSubgridParticleWallContact.h.

131 {
132 return normal;
133 }

References olb::STLtriangle< T >::normal.

◆ getPointToEdgeDistances() [1/2]

template<typename T >
bool olb::STLtriangle< T >::getPointToEdgeDistances ( const Vector< T, 3 > & input,
Vector< T, 3 > & output,
T sensitivity = 1.e-15 )

Returns true if the point is on a edge (smaller than sensitivity) and gives the perpendicular distances to the edges in output https://www.math.kit.edu/ianm2/lehre/am22016s/media/distance-harvard.pdf.

Definition at line 328 of file stlReader.hh.

329{
330 auto P1 = point[0];
331 auto P2 = point[1];
332 output[0] = norm(crossProduct3D(P2-input,P1-P2))/norm(P1-P2);
333 P1 = point[0];
334 P2 = point[2];
335 output[1] = norm(crossProduct3D(P2-input,P1-P2))/norm(P1-P2);
336 P1 = point[1];
337 P2 = point[2];
338 output[2] = norm(crossProduct3D(P2-input,P1-P2))/norm(P1-P2);
339 return true;
340}
constexpr T norm(const ScalarVector< T, D, IMPL > &a) any_platform
Euclidean vector norm.

References olb::crossProduct3D(), and olb::norm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getPointToEdgeDistances() [2/2]

template<typename T >
bool olb::STLtriangle< T >::getPointToEdgeDistances ( const Vector< T, 3 > & input,
Vector< T, 3 > & output,
T sensitivity = 1.e-15 )

Returns true if the point is on a edge (smaller than sensitivity) and gives the perpendicular distances to the edges in output https://www.math.kit.edu/ianm2/lehre/am22016s/media/distance-harvard.pdf.

◆ init() [1/2]

template<typename T >
void olb::STLtriangle< T >::init ( )

Initializes triangle and precomputes member variables.

Definition at line 56 of file stlReader.hh.

57{
58 Vector<T,3> A = point[0];
59 Vector<T,3> B = point[1];
60 Vector<T,3> C = point[2];
61 Vector<T,3> b, c;
62 T bb = 0., bc = 0., cc = 0.;
63
64 for (int i = 0; i < 3; i++) {
65 b[i] = B[i] - A[i];
66 c[i] = C[i] - A[i];
67 bb += b[i] * b[i];
68 bc += b[i] * c[i];
69 cc += c[i] * c[i];
70 }
71
72 normal[0] = b[1] * c[2] - b[2] * c[1];
73 normal[1] = b[2] * c[0] - b[0] * c[2];
74 normal[2] = b[0] * c[1] - b[1] * c[0];
75
76 T norm = util::sqrt(
77 util::pow(normal[0], 2) + util::pow(normal[1], 2) + util::pow(normal[2], 2));
78 normal[0] /= norm;
79 normal[1] /= norm;
80 normal[2] /= norm;
81
82 T D = 1.0 / (cc * bb - bc * bc);
83 T bbD = bb * D;
84 T bcD = bc * D;
85 T ccD = cc * D;
86
87 kBeta = 0.;
88 kGamma = 0.;
89 d = 0.;
90
91 for (int i = 0; i < 3; i++) {
92 uBeta[i] = b[i] * ccD - c[i] * bcD;
93 uGamma[i] = c[i] * bbD - b[i] * bcD;
94 kBeta -= A[i] * uBeta[i];
95 kGamma -= A[i] * uGamma[i];
96 d += A[i] * normal[i];
97 }
98}
platform_constant int c[Q][D]
Definition functions.h:57
Expr sqrt(Expr x)
Definition expr.cpp:225
Expr pow(Expr base, Expr exp)
Definition expr.cpp:235

References olb::norm(), olb::util::pow(), and olb::util::sqrt().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ init() [2/2]

template<typename T >
void olb::STLtriangle< T >::init ( )

Initializes triangle and precomputes member variables.

◆ isEdgePoint() [1/2]

template<typename T >
bool olb::STLtriangle< T >::isEdgePoint ( const Vector< T, 3 > & input,
Vector< T, 3 > & P1,
Vector< T, 3 > & P2,
T sensitivity = 1.e-15 )

Returns true if is near edge (smaller than sensitivity) and not near vortex and saves in P1 and P2 the vortex points of the edge.

Definition at line 343 of file stlReader.hh.

344{
345 using namespace std;
346 if(input[0] < sensitivity && input[1] >= sensitivity && input[2] >= sensitivity )
347 {
348 P1 = point[0];
349 P2 = point[1];
350 //cout << "edge point " << P1 << " " << P2 << std::endl;
351 return true;
352 }
353 if(input[0] >= sensitivity && input[1] < sensitivity && input[2] >= sensitivity )
354 {
355 P1 = point[0];
356 P2 = point[2];
357 //cout << "edge point" << P1 << " " << P2 << std::endl;
358 return true;
359 }
360 if(input[0] >= sensitivity && input[1] >= sensitivity && input[2] < sensitivity )
361 {
362 P1 = point[1];
363 P2 = point[2];
364 //cout << "edge point" << P1 << " " << P2 << std::endl;
365 return true;
366 }
367 return false;
368}
+ Here is the caller graph for this function:

◆ isEdgePoint() [2/2]

template<typename T >
bool olb::STLtriangle< T >::isEdgePoint ( const Vector< T, 3 > & input,
Vector< T, 3 > & P1,
Vector< T, 3 > & P2,
T sensitivity = 1.e-15 )

Returns true if is near edge (smaller than sensitivity) and not near vortex and saves in P1 and P2 the vortex points of the edge.

◆ isPointInside() [1/2]

template<typename T >
bool olb::STLtriangle< T >::isPointInside ( const PhysR< T, 3 > & pt) const

Check whether a point is inside a triangle.

Definition at line 136 of file stlReader.hh.

137{
138 // tests with T=double and T=float show that the epsilon must be increased
139 const T epsilon = std::numeric_limits<BaseType<T>>::epsilon()*T(10);
140
141 const T beta = pt * uBeta + kBeta;
142 const T gamma = pt * uGamma + kGamma;
143
144 // check if approximately equal
145 if ( util::nearZero(norm(pt - (point[0] + beta*(point[1]-point[0]) + gamma*(point[2]-point[0]))), epsilon) ) {
146 const T alpha = T(1) - beta - gamma;
147 return (beta >= T(0) || util::nearZero(beta, epsilon))
148 && (gamma >= T(0) || util::nearZero(gamma, epsilon))
149 && (alpha >= T(0) || util::nearZero(alpha, epsilon));
150 }
151 return false;
152}
bool nearZero(T a) any_platform
return true if a is close to zero
Definition util.h:402

References olb::util::nearZero(), and olb::norm().

+ Here is the call graph for this function:

◆ isPointInside() [2/2]

template<typename T >
bool olb::STLtriangle< T >::isPointInside ( const PhysR< T, 3 > & pt) const

Check whether a point is inside a triangle.

◆ isVortexPoint() [1/2]

template<typename T >
bool olb::STLtriangle< T >::isVortexPoint ( const Vector< T, 3 > & input,
Vector< T, 3 > & P,
T sensitivity = 1.e-15 )

Returns true if is near vortex (smaller than sensitivity) and saves in P the vortex points.

Definition at line 371 of file stlReader.hh.

372{
373 olb::OstreamManager clout = OstreamManager(std::cout, "STLtriangle");
374 using namespace std;
375 if (input[0] < sensitivity && input[1] < sensitivity && input[2] < sensitivity )
376 {
377 cout << "Error isVortexPoint! Possible reduce sensitivity!" << std::endl;
378 return false;
379 }
380 if(input[0] < sensitivity && input[1] < sensitivity)
381 {
382 P = point[0];
383 //cout << "vortex point " << P << std::endl;
384 return true;
385 }
386 if(input[0] < sensitivity && input[2] < sensitivity)
387 {
388 P = point[1];
389 //cout << "vortex point " << P << std::endl;
390 return true;
391 }
392 if(input[1] < sensitivity && input[2] < sensitivity)
393 {
394 P = point[2];
395 //cout << "vortex point " << P << std::endl;
396 return true;
397 }
398 return false;
399}
class for marking output with some text
+ Here is the caller graph for this function:

◆ isVortexPoint() [2/2]

template<typename T >
bool olb::STLtriangle< T >::isVortexPoint ( const Vector< T, 3 > & input,
Vector< T, 3 > & P,
T sensitivity = 1.e-15 )

Returns true if is near vortex (smaller than sensitivity) and saves in P the vortex points.

◆ operator=() [1/2]

template<typename T >
STLtriangle< T > & olb::STLtriangle< T >::operator= ( STLtriangle< T > const & tri)
inline

Operator= equals.

Definition at line 83 of file stlReader.h.

84 {
85 point = tri.point;
86 normal = tri.normal;
87 uBeta = tri.uBeta;
88 uGamma = tri.uGamma;
89 d = tri.d;
90 kBeta = tri.kBeta;
91 kGamma = tri.kGamma;
92 return *this;
93 };
static constexpr unsigned d

References olb::STLtriangle< T >::d, olb::STLtriangle< T >::kBeta, olb::STLtriangle< T >::kGamma, olb::STLtriangle< T >::normal, olb::STLtriangle< T >::point, olb::STLtriangle< T >::uBeta, and olb::STLtriangle< T >::uGamma.

◆ operator=() [2/2]

template<typename T >
STLtriangle< T > & olb::STLtriangle< T >::operator= ( STLtriangle< T > const & tri)
inline

Operator= equals.

Definition at line 108 of file STLreaderForSubgridParticleWallContact.h.

109 {
110 point = tri.point;
111 normal = tri.normal;
112 uBeta = tri.uBeta;
113 uGamma = tri.uGamma;
114 d = tri.d;
115 kBeta = tri.kBeta;
116 kGamma = tri.kGamma;
117 return *this;
118 };

References olb::STLtriangle< T >::d, olb::STLtriangle< T >::kBeta, olb::STLtriangle< T >::kGamma, olb::STLtriangle< T >::normal, olb::STLtriangle< T >::point, olb::STLtriangle< T >::uBeta, and olb::STLtriangle< T >::uGamma.

◆ testRayIntersect() [1/2]

template<typename T >
bool olb::STLtriangle< T >::testRayIntersect ( const Vector< T, 3 > & pt,
const Vector< T, 3 > & dir,
Vector< T, 3 > & q,
T & alpha,
const T & rad = T(),
bool print = false )

Test intersection between ray and triangle.

Parameters
ptRaypoint
dirDirection
qPoint of intersection (if intersection occurs)
alphaExplained in http://www.uninformativ.de/bin/RaytracingSchnitttests-76a577a-CC-BY.pdf page 7-12 q = pt + alpha * dir
radIt's complicated. Imagine you have a sphere with radius rad moving a long the ray. Then q becomes the first point of the sphere to touch the triangle.

Definition at line 164 of file stlReader.hh.

168{
169 T rn = 0.;
170 Vector<T,3> testPt = pt + rad * normal;
171 /* Vector<T,3> help; */
172
173 for (int i = 0; i < 3; i++) {
174 rn += dir[i] * normal[i];
175 }
176#ifdef OLB_DEBUG
177
178 if (print) {
179 std::cout << "Pt: " << pt[0] << " " << pt[1] << " " << pt[2] << std::endl;
180 }
181 if (print)
182 std::cout << "testPt: " << testPt[0] << " " << testPt[1] << " " << testPt[2]
183 << std::endl;
184 if (print)
185 std::cout << "PosNeg: "
186 << normal[0] * testPt[0] + normal[1] * testPt[1] + normal[2] * testPt[2]
187 - d << std::endl;
188 if (print)
189 std::cout << "Normal: " << normal[0] << " " << normal[1] << " " << normal[2]
190 << std::endl;
191#endif
192
193 // Schnitttest Flugrichtung -> Ebene
194 if (util::fabs(rn) < std::numeric_limits<T>::epsilon()) {
195#ifdef OLB_DEBUG
196 if (print) {
197 std::cout << "FALSE 1" << std::endl;
198 }
199#endif
200 return false;
201 }
202 alpha = d - testPt[0] * normal[0] - testPt[1] * normal[1] - testPt[2] * normal[2];
203 // alpha -= testPt[i] * normal[i];
204 alpha /= rn;
205
206 // Abstand Partikel Ebene
207 if (alpha < -std::numeric_limits<T>::epsilon()) {
208#ifdef OLB_DEBUG
209 if (print) {
210 std::cout << "FALSE 2" << std::endl;
211 }
212#endif
213 return false;
214 }
215 for (int i = 0; i < 3; i++) {
216 q[i] = testPt[i] + alpha * dir[i];
217 }
218 T beta = kBeta;
219 for (int i = 0; i < 3; i++) {
220 beta += uBeta[i] * q[i];
221 }
222#ifdef OLB_DEBUG
223 T dist = util::sqrt(
224 util::pow(q[0] - testPt[0], 2) + util::pow(q[1] - testPt[1], 2)
225 + util::pow(q[2] - testPt[2], 2));
226#endif
227
228 // Schnittpunkt q in der Ebene?
229 if (beta < -std::numeric_limits<T>::epsilon()) {
230#ifdef OLB_DEBUG
231
232 if (print) {
233 std::cout << "FALSE 3 BETA " << beta << " DIST " << dist << std::endl;
234 }
235#endif
236 return false;
237 }
238 T gamma = kGamma;
239 for (int i = 0; i < 3; i++) {
240 gamma += uGamma[i] * q[i];
241 }
242 if (gamma < -std::numeric_limits<T>::epsilon()) {
243#ifdef OLB_DEBUG
244 if (print) {
245 std::cout << "FALSE 4 GAMMA " << gamma << " DIST " << dist << std::endl;
246 }
247#endif
248 return false;
249 }
250 if (1. - beta - gamma < -std::numeric_limits<T>::epsilon()) {
251#ifdef OLB_DEBUG
252 if (print)
253 std::cout << "FALSE 5 VAL " << 1 - beta - gamma << " DIST " << dist
254 << std::endl;
255#endif
256 return false;
257 }
258#ifdef OLB_DEBUG
259 if (print) {
260 std::cout << "TRUE" << " GAMMA " << gamma << " BETA " << beta << std::endl;
261 }
262#endif
263 return true;
264}
constexpr int q() any_platform
Definition functions.h:140
Expr fabs(Expr x)
Definition expr.cpp:230

References olb::util::fabs(), olb::util::pow(), and olb::util::sqrt().

+ Here is the call graph for this function:

◆ testRayIntersect() [2/2]

template<typename T >
bool olb::STLtriangle< T >::testRayIntersect ( const Vector< T, 3 > & pt,
const Vector< T, 3 > & dir,
Vector< T, 3 > & q,
T & alpha,
const T & rad = T(),
bool print = false )

Test intersection between ray and triangle.

Parameters
ptRaypoint
dirDirection
qPoint of intersection (if intersection occurs)
alphaExplained in http://www.uninformativ.de/bin/RaytracingSchnitttests-76a577a-CC-BY.pdf page 7-12 q = pt + alpha * dir
radIt's complicated. Imagine you have a sphere with radius rad moving a long the ray. Then q becomes the first point of the sphere to touch the triangle.

Member Data Documentation

◆ d

template<typename T >
T olb::STLtriangle< T >::d

Definition at line 75 of file stlReader.h.

◆ kBeta

template<typename T >
T olb::STLtriangle< T >::kBeta

Definition at line 75 of file stlReader.h.

◆ kGamma

template<typename T >
T olb::STLtriangle< T >::kGamma

Definition at line 75 of file stlReader.h.

◆ normal

template<typename T >
Vector< T, 3 > olb::STLtriangle< T >::normal

normal of triangle

Definition at line 70 of file stlReader.h.

◆ point [1/2]

template<typename T >
std::vector<Vector<T,3> > olb::STLtriangle< T >::point

A triangle contains 3 Points.

Definition at line 67 of file stlReader.h.

◆ point [2/2]

template<typename T >
std::vector<Vertex<T,3> > olb::STLtriangle< T >::point

A triangle contains 3 Points.

Definition at line 92 of file STLreaderForSubgridParticleWallContact.h.

◆ uBeta

template<typename T >
Vector< T, 3 > olb::STLtriangle< T >::uBeta

variables explained in http://www.uninformativ.de/bin/RaytracingSchnitttests-76a577a-CC-BY.pdf page 7-12 precomputed for speedup

Definition at line 74 of file stlReader.h.

◆ uGamma

template<typename T >
Vector< T, 3 > olb::STLtriangle< T >::uGamma

Definition at line 74 of file stlReader.h.


The documentation for this struct was generated from the following files: