hemocell
Loading...
Searching...
No Matches
mollerTrumbore.h
Go to the documentation of this file.
1/*
2This file is part of the HemoCell library
3
4HemoCell is developed and maintained by the Computational Science Lab
5in the University of Amsterdam. Any questions or remarks regarding this library
6can be sent to: info@hemocell.eu
7
8When using the HemoCell library in scientific work please cite the
9corresponding paper: https://doi.org/10.3389/fphys.2017.00563
10
11The HemoCell library is free software: you can redistribute it and/or
12modify it under the terms of the GNU Affero General Public License as
13published by the Free Software Foundation, either version 3 of the
14License, or (at your option) any later version.
15
16The library is distributed in the hope that it will be useful,
17but WITHOUT ANY WARRANTY; without even the implied warranty of
18MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19GNU Affero General Public License for more details.
20
21You should have received a copy of the GNU Affero General Public License
22along with this program. If not, see <http://www.gnu.org/licenses/>.
23*/
24#ifndef HEMO_MOLLER_H
25#define HEMO_MOLLER_H
26
27#include "array.h" // Need to make pointers to particle object
28
29namespace hemo {
30inline int MollerTrumbore(const hemo::Array<T, 3> & v0, const hemo::Array<T, 3> & v1, const hemo::Array<T, 3> & v2,
31 hemo::Array<plint, 3> & rayPoint) {
32 const T EPSILON = 0.0000001;
33 T det, invDet, u, v; // Some floats
34 hemo::Array<T, 3> edge1, edge2, pvec, svec, qvec;
35 hemo::Array<T, 3> rayVector = {(T)-40, (T)-40, (T)-40};
36 hemo::Array<plint, 3> & rayOrigin = rayPoint;
37
38 // Define edges
39 edge1 = v1 - v0;
40 edge2 = v2 - v0;
41
42 pvec = hemo::crossProduct(rayVector, edge2);
43 det = hemo::dot(edge1, pvec);
44
45 if (det > -EPSILON && det < EPSILON) { return 0; }
46
47 invDet = 1 / det;
48
49 // Construct s
50 svec = rayOrigin - v0;
51 u = invDet * hemo::dot(svec, pvec);
52
53 if (u < 0.0 || u > 1.0) { return 0; }
54
55 qvec = hemo::crossProduct(svec, edge1);
56 v = invDet * hemo::dot(rayVector, qvec);
57
58 if (v < 0.0 || u + v > 1.0) { return 0; }
59
60 // Check where the intersection point is
61 float t = invDet * hemo::dot(edge2, qvec);
62
63 if (t > EPSILON) { return 1; }
64
65 return 0;
66}
67}
68
69#endif
double T
Definition constant_defaults.h:137
Definition config.cpp:37
void crossProduct(const Array< _Tp, 3 > &one, const Array< _Tp2, 3 > &two, Array< _Tp3, 3 > &result)
Definition array.h:162
int MollerTrumbore(const hemo::Array< T, 3 > &v0, const hemo::Array< T, 3 > &v1, const hemo::Array< T, 3 > &v2, hemo::Array< plint, 3 > &rayPoint)
Definition mollerTrumbore.h:30
_Tp dot(const Array< _Tp, _Nm > &one, const Array< _Tp, _Nm > &two)
Definition array.h:183
Definition array.h:40