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 {
30 inline int MollerTrumbore(const hemo::Array<T,3> & v0, const hemo::Array<T,3> & v1,
31 const hemo::Array<T,3> & v2, 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) {
46 return 0;
47 }
48
49 invDet = 1/det;
50
51 // Construct s
52 svec = rayOrigin - v0;
53 u = invDet*hemo::dot(svec, pvec);
54
55 if (u < 0.0 || u > 1.0) {
56 return 0;
57 }
58
59 qvec = hemo::crossProduct(svec, edge1);
60 v = invDet * hemo::dot(rayVector, qvec);
61
62 if (v < 0.0 || u + v > 1.0) {
63 return 0;
64 }
65
66 // Check where the intersection point is
67 float t = invDet*hemo::dot(edge2, qvec);
68
69 if (t > EPSILON) {
70 return 1;
71 }
72
73 return 0;
74 }
75}
76
77#endif
double T
Definition constant_defaults.h:118
Definition config.cpp:34
void crossProduct(const Array< _Tp, 3 > &one, const Array< _Tp2, 3 > &two, Array< _Tp3, 3 > &result)
Definition array.h:199
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:220
Definition array.h:39