\doxysection{Ray.\+h}
\hypertarget{_ray_8h_source}{}\label{_ray_8h_source}\index{src/Ray.h@{src/Ray.h}}

\begin{DoxyCode}{0}
\DoxyCodeLine{00001\ }
\DoxyCodeLine{00009\ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ T>}
\DoxyCodeLine{00010\ \textcolor{keyword}{class\ }\mbox{\hyperlink{class_ray}{Ray}}\ \{}
\DoxyCodeLine{00011\ }
\DoxyCodeLine{00012\ \ \ \ \ \textcolor{keyword}{private}:}
\DoxyCodeLine{00013\ \ \ \ \ \ \ \ \ \mbox{\hyperlink{class_matrix}{Matrix<T>}}\ origin;\ \ \ \ \ \ \ \ \ \ \ }
\DoxyCodeLine{00014\ \ \ \ \ \ \ \ \ \mbox{\hyperlink{class_matrix}{Matrix<T>}}\ velocity;\ \ \ \ \ \ \ \ \ }
\DoxyCodeLine{00015\ \ \ \ \ \ \ \ \ T\ mass\_flux;\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ }
\DoxyCodeLine{00016\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{unsigned}\ \textcolor{keywordtype}{int}\ children;\ \ \ \ \ \ }
\DoxyCodeLine{00017\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{int}\ spawn\_vertex\_index;\ \ \ \ \ }
\DoxyCodeLine{00018\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{bool}\ failed\ =\ \textcolor{keyword}{false};\ \ \ \ \ \ \ \ }
\DoxyCodeLine{00019\ }
\DoxyCodeLine{00020\ \ \ \ \ \textcolor{keyword}{public}:}
\DoxyCodeLine{00026\ \ \ \ \ \ \ \ \ \mbox{\hyperlink{class_ray_a955149e799dfd119fbaf748bb8669306}{Ray}}();}
\DoxyCodeLine{00027\ }
\DoxyCodeLine{00039\ \ \ \ \ \ \ \ \ \mbox{\hyperlink{class_ray_a955149e799dfd119fbaf748bb8669306}{Ray}}(\mbox{\hyperlink{class_matrix}{Matrix<T>}}\&\ origin,\ \mbox{\hyperlink{class_matrix}{Matrix<T>}}\&\ velocity,\ T\ m\_dot,\ \textcolor{keywordtype}{unsigned}\ \textcolor{keywordtype}{int}\ children,\ \textcolor{keywordtype}{int}\ spawn\_vertex\_index);}
\DoxyCodeLine{00040\ }
\DoxyCodeLine{00048\ \ \ \ \ \ \ \ \ \mbox{\hyperlink{class_ray_a955149e799dfd119fbaf748bb8669306}{Ray}}(\textcolor{keyword}{const}\ \mbox{\hyperlink{class_ray}{Ray<T>}}\&\ other);}
\DoxyCodeLine{00049\ }
\DoxyCodeLine{00057\ \ \ \ \ \ \ \ \ \mbox{\hyperlink{class_ray_a955149e799dfd119fbaf748bb8669306}{Ray}}(\mbox{\hyperlink{class_ray}{Ray<T>}}\&\&\ other);}
\DoxyCodeLine{00058\ }
\DoxyCodeLine{00064\ \ \ \ \ \ \ \ \ \mbox{\hyperlink{class_ray_afd7bbae2cfc1054fdc8fe9283304655c}{\string~Ray}}();}
\DoxyCodeLine{00065\ }
\DoxyCodeLine{00074\ \ \ \ \ \ \ \ \ \mbox{\hyperlink{class_ray}{Ray}}\&\ \mbox{\hyperlink{class_ray_ab5834ffcc129b2c1cf96e1fac85305cc}{operator=}}(\textcolor{keyword}{const}\ \mbox{\hyperlink{class_ray}{Ray}}\&\ other);}
\DoxyCodeLine{00075\ }
\DoxyCodeLine{00084\ \ \ \ \ \ \ \ \ \mbox{\hyperlink{class_ray}{Ray}}\&\ \mbox{\hyperlink{class_ray_ab5834ffcc129b2c1cf96e1fac85305cc}{operator=}}(\mbox{\hyperlink{class_ray}{Ray}}\&\&\ other);}
\DoxyCodeLine{00085\ }
\DoxyCodeLine{00091\ \ \ \ \ \ \ \ \ \mbox{\hyperlink{class_matrix}{Matrix<T>}}\&\ \mbox{\hyperlink{class_ray_a4bc1a761f283f394fd0c166ca387ec08}{get\_velocity}}()\ \{\ \textcolor{keywordflow}{return}\ this-\/>velocity;\ \}}
\DoxyCodeLine{00092\ }
\DoxyCodeLine{00098\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{void}\ \mbox{\hyperlink{class_ray_a91096132b3916bc4343b5ba57b210ef0}{set\_velocity}}(\mbox{\hyperlink{class_matrix}{Matrix<T>}}\ new\_velocity)\ \{\ this-\/>velocity\ =\ new\_velocity;\ \}}
\DoxyCodeLine{00099\ }
\DoxyCodeLine{00105\ \ \ \ \ \ \ \ \ \mbox{\hyperlink{class_matrix}{Matrix<T>}}\&\ \mbox{\hyperlink{class_ray_afe655d44c6fdf82302a23277c70ad855}{get\_origin}}()\ \{\ \textcolor{keywordflow}{return}\ this-\/>origin;\ \}}
\DoxyCodeLine{00106\ }
\DoxyCodeLine{00112\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{void}\ \mbox{\hyperlink{class_ray_a147d4777c675a602d40d477b5a89ca1e}{set\_origin}}(\mbox{\hyperlink{class_matrix}{Matrix<T>}}\ new\_origin)\ \{\ this-\/>origin\ =\ new\_origin;\ \}}
\DoxyCodeLine{00113\ }
\DoxyCodeLine{00119\ \ \ \ \ \ \ \ \ T\ \mbox{\hyperlink{class_ray_a4f4554397e4d6cda881952bd19ee3ea6}{get\_mass\_flux}}()\ \{\ \textcolor{keywordflow}{return}\ mass\_flux;\ \}}
\DoxyCodeLine{00120\ }
\DoxyCodeLine{00126\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{void}\ \mbox{\hyperlink{class_ray_a06880ade4cf7d629dae6c9b95f714735}{set\_mass\_flux}}(T\ mass\_flux)\ \{\ this-\/>mass\_flux\ =\ mass\_flux;\ \}}
\DoxyCodeLine{00127\ }
\DoxyCodeLine{00142\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{bool}\ \mbox{\hyperlink{class_ray_a86c8b57e8e18c08a12cbdfa7595c29b6}{check\_vertex\_collision}}(\mbox{\hyperlink{class_matrix}{Matrix<T>}}\&\ p1,\ \mbox{\hyperlink{class_matrix}{Matrix<T>}}\&\ p2,\ \mbox{\hyperlink{class_matrix}{Matrix<T>}}\&\ p3,\ \mbox{\hyperlink{class_matrix}{Matrix<T>}}\&\ normal,\ \mbox{\hyperlink{class_matrix}{Matrix<T>}}\&\ col\_position,\ T\&\ distance);}
\DoxyCodeLine{00143\ }
\DoxyCodeLine{00150\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{bool}\ \mbox{\hyperlink{class_ray_ae5c50e5329252b50b03ff0da1002287d}{check\_bb\_collision}}(\mbox{\hyperlink{class_matrix}{Matrix<T>}}\&\ bb);}
\DoxyCodeLine{00151\ }
\DoxyCodeLine{00164\ \ \ \ \ \ \ \ \ std::vector<Ray<T>>\ \mbox{\hyperlink{class_ray_abd9d51036947e4b7e6e145d9095e51a1}{propagate}}(\mbox{\hyperlink{class_geometry}{Geometry<T>}}\&\ geometry,\ \textcolor{keyword}{const}\ \mbox{\hyperlink{class_gas}{Gas<T>}}\&\ gas,\ \textcolor{keywordtype}{void}\ (*kernel)(T*,\ T*,\ T*,\ T*,\ T*),\ \textcolor{keywordtype}{unsigned}\ \textcolor{keywordtype}{int}*\ collision\_index);}
\DoxyCodeLine{00165\ \};}
\DoxyCodeLine{00166\ }
\DoxyCodeLine{00172\ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ T>}
\DoxyCodeLine{00173\ \mbox{\hyperlink{class_ray_a955149e799dfd119fbaf748bb8669306}{Ray<T>::Ray}}()\ \{}
\DoxyCodeLine{00174\ \ \ \ \ origin\ =\ \mbox{\hyperlink{class_matrix}{Matrix<T>}}(3,\ 1,\ \{0.0,\ 0.0,\ 0.0\});}
\DoxyCodeLine{00175\ \ \ \ \ velocity\ =\ \mbox{\hyperlink{class_matrix}{Matrix<T>}}(3,\ 1,\ \{0.0,\ 0.0,\ 0.0\});}
\DoxyCodeLine{00176\ \ \ \ \ mass\_flux\ =\ 0.0;}
\DoxyCodeLine{00177\ \ \ \ \ children\ =\ 0;}
\DoxyCodeLine{00178\ \ \ \ \ spawn\_vertex\_index\ =\ -\/1;}
\DoxyCodeLine{00179\ \}}
\DoxyCodeLine{00180\ }
\DoxyCodeLine{00192\ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ T>}
\DoxyCodeLine{00193\ \mbox{\hyperlink{class_ray_a955149e799dfd119fbaf748bb8669306}{Ray<T>::Ray}}(\mbox{\hyperlink{class_matrix}{Matrix<T>}}\&\ origin,\ \mbox{\hyperlink{class_matrix}{Matrix<T>}}\&\ velocity,\ T\ m\_dot,\ \textcolor{keywordtype}{unsigned}\ \textcolor{keywordtype}{int}\ children,\ \textcolor{keywordtype}{int}\ spawn\_vertex\_index)}
\DoxyCodeLine{00194\ \ \ \ \ :\ origin(origin),\ velocity(velocity),\ mass\_flux(m\_dot),\ children(children),\ spawn\_vertex\_index(spawn\_vertex\_index)\ \{\}}
\DoxyCodeLine{00195\ }
\DoxyCodeLine{00203\ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ T>}
\DoxyCodeLine{00204\ \mbox{\hyperlink{class_ray_a955149e799dfd119fbaf748bb8669306}{Ray<T>::Ray}}(\textcolor{keyword}{const}\ \mbox{\hyperlink{class_ray}{Ray<T>}}\&\ other)\ }
\DoxyCodeLine{00205\ \ \ \ \ :\ origin(other.origin),\ velocity(other.velocity),\ children(other.children),\ mass\_flux(other.mass\_flux),\ spawn\_vertex\_index(other.spawn\_vertex\_index)\ \{\}}
\DoxyCodeLine{00206\ }
\DoxyCodeLine{00214\ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ T>}
\DoxyCodeLine{00215\ \mbox{\hyperlink{class_ray_a955149e799dfd119fbaf748bb8669306}{Ray<T>::Ray}}(\mbox{\hyperlink{class_ray}{Ray<T>}}\&\&\ other)}
\DoxyCodeLine{00216\ \ \ \ \ :\ origin(other.origin),\ velocity(other.velocity),\ children(other.children),\ mass\_flux(other.mass\_flux),\ spawn\_vertex\_index(other.spawn\_vertex\_index)\ \{}
\DoxyCodeLine{00217\ \ \ \ \ other.children\ =\ 0;}
\DoxyCodeLine{00218\ \ \ \ \ other.mass\_flux\ =\ 0.0;}
\DoxyCodeLine{00219\ \ \ \ \ other.spawn\_vertex\_index\ =\ 0;}
\DoxyCodeLine{00220\ \}}
\DoxyCodeLine{00221\ }
\DoxyCodeLine{00227\ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ T>}
\DoxyCodeLine{00228\ \mbox{\hyperlink{class_ray_afd7bbae2cfc1054fdc8fe9283304655c}{Ray<T>::\string~Ray}}()\ \{}
\DoxyCodeLine{00229\ \ \ \ \ children\ =\ 0;}
\DoxyCodeLine{00230\ \ \ \ \ mass\_flux\ =\ 0.0;}
\DoxyCodeLine{00231\ \}}
\DoxyCodeLine{00232\ }
\DoxyCodeLine{00241\ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ T>}
\DoxyCodeLine{00242\ \mbox{\hyperlink{class_ray}{Ray<T>}}\&\ \mbox{\hyperlink{class_ray_ab5834ffcc129b2c1cf96e1fac85305cc}{Ray<T>::operator=}}(\textcolor{keyword}{const}\ \mbox{\hyperlink{class_ray}{Ray<T>}}\&\ other)\ \{}
\DoxyCodeLine{00243\ \ \ \ \ origin\ =\ other.origin;}
\DoxyCodeLine{00244\ \ \ \ \ velocity\ =\ other.velocity;}
\DoxyCodeLine{00245\ \ \ \ \ mass\_flux\ =\ other.mass\_flux;}
\DoxyCodeLine{00246\ \ \ \ \ children\ =\ other.children;}
\DoxyCodeLine{00247\ \ \ \ \ spawn\_vertex\_index\ =\ other.spawn\_vertex\_index;}
\DoxyCodeLine{00248\ \ \ \ \ \textcolor{keywordflow}{return}\ *\textcolor{keyword}{this};}
\DoxyCodeLine{00249\ \}}
\DoxyCodeLine{00250\ }
\DoxyCodeLine{00259\ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ T>}
\DoxyCodeLine{00260\ \mbox{\hyperlink{class_ray}{Ray<T>}}\&\ \mbox{\hyperlink{class_ray_ab5834ffcc129b2c1cf96e1fac85305cc}{Ray<T>::operator=}}(\mbox{\hyperlink{class_ray}{Ray<T>}}\&\&\ other)\ \{}
\DoxyCodeLine{00261\ \ \ \ \ origin\ =\ other.origin;}
\DoxyCodeLine{00262\ \ \ \ \ velocity\ =\ other.velocity;}
\DoxyCodeLine{00263\ \ \ \ \ mass\_flux\ =\ other.mass\_flux;}
\DoxyCodeLine{00264\ \ \ \ \ children\ =\ other.children;}
\DoxyCodeLine{00265\ \ \ \ \ spawn\_vertex\_index\ =\ other.spawn\_vertex\_index;}
\DoxyCodeLine{00266\ }
\DoxyCodeLine{00267\ \ \ \ \ \textcolor{comment}{//\ Reset\ the\ properties\ of\ the\ moved\ ray}}
\DoxyCodeLine{00268\ \ \ \ \ other.children\ =\ 0;}
\DoxyCodeLine{00269\ \ \ \ \ other.mass\_flux\ =\ 0.0;}
\DoxyCodeLine{00270\ \ \ \ \ other.spawn\_vertex\_index\ =\ 0;}
\DoxyCodeLine{00271\ \ \ \ \ \textcolor{keywordflow}{return}\ *\textcolor{keyword}{this};}
\DoxyCodeLine{00272\ \}}
\DoxyCodeLine{00273\ }
\DoxyCodeLine{00289\ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ T>}
\DoxyCodeLine{00290\ \textcolor{keywordtype}{bool}\ \mbox{\hyperlink{class_ray_a86c8b57e8e18c08a12cbdfa7595c29b6}{Ray<T>::check\_vertex\_collision}}(\mbox{\hyperlink{class_matrix}{Matrix<T>}}\&\ p1,\ \mbox{\hyperlink{class_matrix}{Matrix<T>}}\&\ p2,\ \mbox{\hyperlink{class_matrix}{Matrix<T>}}\&\ p3,\ \mbox{\hyperlink{class_matrix}{Matrix<T>}}\&\ normal,\ \mbox{\hyperlink{class_matrix}{Matrix<T>}}\&\ col\_position,\ T\&\ distance)\ \{}
\DoxyCodeLine{00291\ \ \ \ \ }
\DoxyCodeLine{00292\ \ \ \ \ \textcolor{keyword}{const}\ T\ EPSILON\ =\ 1e-\/15;\ \textcolor{comment}{//\ Small\ tolerance\ for\ floating-\/point\ comparisons}}
\DoxyCodeLine{00293\ \ \ \ \ \mbox{\hyperlink{class_matrix}{Matrix<T>}}\ edge1(3,\ 1),\ edge2(3,\ 1),\ h(3,\ 1),\ s(3,\ 1),\ q(3,\ 1);}
\DoxyCodeLine{00294\ \ \ \ \ \mbox{\hyperlink{class_matrix}{Matrix<T>}}\ direction(3,\ 1);}
\DoxyCodeLine{00295\ \ \ \ \ direction\ =\ velocity\ /\ velocity.\mbox{\hyperlink{class_matrix_a7ef7109486e3ba18eced478f5cc568cc}{norm}}();\ }
\DoxyCodeLine{00296\ \ \ \ \ T\ a,\ f,\ u,\ v;}
\DoxyCodeLine{00297\ }
\DoxyCodeLine{00298\ \ \ \ \ \textcolor{comment}{//\ Compute\ the\ two\ edge\ vectors\ of\ the\ triangle}}
\DoxyCodeLine{00299\ \ \ \ \ edge1\ =\ p2\ -\/\ p1;}
\DoxyCodeLine{00300\ \ \ \ \ edge2\ =\ p3\ -\/\ p1;}
\DoxyCodeLine{00301\ }
\DoxyCodeLine{00302\ \ \ \ \ \textcolor{comment}{//\ Calculate\ the\ determinant\ (cross\ product\ of\ ray\ direction\ and\ edge2)}}
\DoxyCodeLine{00303\ \ \ \ \ h\ =\ direction.\mbox{\hyperlink{class_matrix_a03b588592a081b3bcba0e121ca0164b1}{cross}}(edge2);}
\DoxyCodeLine{00304\ \ \ \ \ a\ =\ edge1.\mbox{\hyperlink{class_matrix_afcee4f858a2f7dfde3dc28e6d1d32c59}{tr}}().\mbox{\hyperlink{class_matrix_a33b9a1b469adfb4f002564ba874f41c9}{dot}}(h)(0,\ 0);}
\DoxyCodeLine{00305\ }
\DoxyCodeLine{00306\ \ \ \ \ \textcolor{comment}{//\ Check\ if\ the\ ray\ is\ parallel\ to\ the\ triangle}}
\DoxyCodeLine{00307\ \ \ \ \ \textcolor{keywordflow}{if}\ (a\ >\ -\/EPSILON\ \&\&\ a\ <\ EPSILON)\ \{}
\DoxyCodeLine{00308\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ \textcolor{keyword}{false};\ \textcolor{comment}{//\ Parallel\ ray}}
\DoxyCodeLine{00309\ \ \ \ \ \}}
\DoxyCodeLine{00310\ }
\DoxyCodeLine{00311\ \ \ \ \ \textcolor{comment}{//\ Calculate\ the\ ray-\/triangle\ intersection\ using\ barycentric\ coordinates}}
\DoxyCodeLine{00312\ \ \ \ \ f\ =\ 1.0\ /\ a;}
\DoxyCodeLine{00313\ \ \ \ \ s\ =\ (origin\ -\/\ p1);}
\DoxyCodeLine{00314\ \ \ \ \ u\ =\ f\ *\ s.\mbox{\hyperlink{class_matrix_afcee4f858a2f7dfde3dc28e6d1d32c59}{tr}}().\mbox{\hyperlink{class_matrix_a33b9a1b469adfb4f002564ba874f41c9}{dot}}(h)(0,\ 0);}
\DoxyCodeLine{00315\ }
\DoxyCodeLine{00316\ \ \ \ \ \textcolor{keywordflow}{if}\ (u\ <\ -\/EPSILON\ ||\ u\ >\ 1.0\ +\ EPSILON)\ \{}
\DoxyCodeLine{00317\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ \textcolor{keyword}{false};\ \textcolor{comment}{//\ No\ intersection}}
\DoxyCodeLine{00318\ \ \ \ \ \}}
\DoxyCodeLine{00319\ }
\DoxyCodeLine{00320\ \ \ \ \ q\ =\ s.\mbox{\hyperlink{class_matrix_a03b588592a081b3bcba0e121ca0164b1}{cross}}(edge1);}
\DoxyCodeLine{00321\ \ \ \ \ v\ =\ f\ *\ direction.\mbox{\hyperlink{class_matrix_afcee4f858a2f7dfde3dc28e6d1d32c59}{tr}}().\mbox{\hyperlink{class_matrix_a33b9a1b469adfb4f002564ba874f41c9}{dot}}(q)(0,\ 0);}
\DoxyCodeLine{00322\ }
\DoxyCodeLine{00323\ \ \ \ \ \textcolor{keywordflow}{if}\ (v\ <\ -\/EPSILON\ ||\ u\ +\ v\ >\ 1.0\ +\ EPSILON)\ \{}
\DoxyCodeLine{00324\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ \textcolor{keyword}{false};\ \textcolor{comment}{//\ No\ intersection}}
\DoxyCodeLine{00325\ \ \ \ \ \}}
\DoxyCodeLine{00326\ }
\DoxyCodeLine{00327\ \ \ \ \ \textcolor{comment}{//\ Calculate\ the\ intersection\ point}}
\DoxyCodeLine{00328\ \ \ \ \ T\ t\ =\ f\ *\ edge2.tr().dot(q)(0,\ 0);}
\DoxyCodeLine{00329\ }
\DoxyCodeLine{00330\ \ \ \ \ \textcolor{keywordflow}{if}\ (t\ >\ EPSILON)\ \{}
\DoxyCodeLine{00331\ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ Ray\ intersects\ the\ triangle}}
\DoxyCodeLine{00332\ \ \ \ \ \ \ \ \ distance\ =\ fabs(t);}
\DoxyCodeLine{00333\ \ \ \ \ \ \ \ \ col\_position\ =\ origin\ +\ direction\ *\ t;}
\DoxyCodeLine{00334\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ \textcolor{keyword}{true};}
\DoxyCodeLine{00335\ \ \ \ \ \}\ \textcolor{keywordflow}{else}\ \{}
\DoxyCodeLine{00336\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ \textcolor{keyword}{false};\ \textcolor{comment}{//\ Intersection\ occurs,\ but\ not\ in\ the\ direction\ of\ the\ ray}}
\DoxyCodeLine{00337\ \ \ \ \ \}}
\DoxyCodeLine{00338\ \}}
\DoxyCodeLine{00339\ }
\DoxyCodeLine{00355\ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ T>}
\DoxyCodeLine{00356\ std::vector<Ray<T>>\ \mbox{\hyperlink{class_ray_abd9d51036947e4b7e6e145d9095e51a1}{Ray<T>::propagate}}(\mbox{\hyperlink{class_geometry}{Geometry<T>}}\&\ geometry,\ \textcolor{keyword}{const}\ \mbox{\hyperlink{class_gas}{Gas<T>}}\&\ gas,\ \textcolor{keywordtype}{void}\ (*kernel)(T*,\ T*,\ T*,\ T*,\ T*),\ \textcolor{keywordtype}{unsigned}\ \textcolor{keywordtype}{int}*\ collision\_index)\ \{}
\DoxyCodeLine{00357\ }
\DoxyCodeLine{00358\ \ \ \ \ std::vector<Ray<T>>\ children\_rays;\ \textcolor{comment}{//\ Vector\ to\ store\ the\ child\ rays\ after\ propagation}}
\DoxyCodeLine{00359\ \ \ \ \ \mbox{\hyperlink{class_matrix}{Matrix<T>}}\ p1\_col(3,\ 1),\ p2\_col(3,\ 1),\ p3\_col(3,\ 1),\ norm\_col(3,\ 1),\ pos\_col(3,\ 1);\ \textcolor{comment}{//\ Collision-\/related\ matrices}}
\DoxyCodeLine{00360\ \ \ \ \ \mbox{\hyperlink{class_matrix}{Matrix<T>}}\ p1\_x\ =\ geometry.get\_p1\_x(),\ p1\_y\ =\ geometry.get\_p1\_y(),\ p1\_z\ =\ geometry.get\_p1\_z();}
\DoxyCodeLine{00361\ \ \ \ \ \mbox{\hyperlink{class_matrix}{Matrix<T>}}\ p2\_x\ =\ geometry.get\_p2\_x(),\ p2\_y\ =\ geometry.get\_p2\_y(),\ p2\_z\ =\ geometry.get\_p2\_z();}
\DoxyCodeLine{00362\ \ \ \ \ \mbox{\hyperlink{class_matrix}{Matrix<T>}}\ p3\_x\ =\ geometry.get\_p3\_x(),\ p3\_y\ =\ geometry.get\_p3\_y(),\ p3\_z\ =\ geometry.get\_p3\_z();}
\DoxyCodeLine{00363\ \ \ \ \ \mbox{\hyperlink{class_matrix}{Matrix<T>}}\ norm\_x\ =\ geometry.get\_norm\_x(),\ norm\_y\ =\ geometry.get\_norm\_y(),\ norm\_z\ =\ geometry.get\_norm\_z();}
\DoxyCodeLine{00364\ \ \ \ \ std::vector<Matrix<T>>\ GSI\_properties(geometry.\mbox{\hyperlink{class_geometry_a04f06f9115074fd95c4f66db48572c30}{get\_GSI\_properties}}());\ \textcolor{comment}{//\ GSI\ (General\ Surface\ Interaction)\ properties}}
\DoxyCodeLine{00365\ \ \ \ \ std::vector<const\ char*>\ GSI\_property\_names(geometry.\mbox{\hyperlink{class_geometry_adf82e0a1da5d92dfefcb1ab63ea2a23c}{get\_GSI\_property\_names}}());\ \textcolor{comment}{//\ Names\ of\ GSI\ properties}}
\DoxyCodeLine{00366\ \ \ \ \ std::vector<Matrix<T>>\ surface\_properties(geometry.\mbox{\hyperlink{class_geometry_a729679f2bcc32ddd36d5b636cfdc79b6}{get\_surface\_properties}}());\ \textcolor{comment}{//\ Surface\ properties\ at\ each\ vertex}}
\DoxyCodeLine{00367\ \ \ \ \ std::vector<const\ char*>\ surface\_property\_names(geometry.\mbox{\hyperlink{class_geometry_a3830df67dee94fccb138a70fa52ea101}{get\_surface\_property\_names}}());\ \textcolor{comment}{//\ Names\ of\ surface\ properties}}
\DoxyCodeLine{00368\ }
\DoxyCodeLine{00369\ \ \ \ \ T*\ GSI\_prop\_col\ =\ \textcolor{keyword}{new}\ T[GSI\_properties.size()\ +\ 1];\ \textcolor{comment}{//\ GSI\ properties\ at\ the\ collision\ point}}
\DoxyCodeLine{00370\ \ \ \ \ T*\ surface\_prop\_col\ =\ \textcolor{keyword}{new}\ T[surface\_properties.size()\ +\ 1];\ \textcolor{comment}{//\ Surface\ properties\ at\ the\ collision\ point}}
\DoxyCodeLine{00371\ \ \ \ \ T\ gas\_prop\_col[5]\ =\ \{gas.\mbox{\hyperlink{class_gas_aae9cf3b82b2eeb0b9ed96e2c973920cb}{get\_temperature}}(),\ gas.\mbox{\hyperlink{class_gas_a7d97eadcb351e8d7d1043771712917fe}{get\_density}}(),\ gas.\mbox{\hyperlink{class_gas_a6bd15f51e80e57db68a0b8763b800fb7}{get\_molar\_mass}}(),\ gas.\mbox{\hyperlink{class_gas_ae17c7893c96ce081e42e19a9a62abdfb}{get\_speed}}()\};\ \textcolor{comment}{//\ Gas\ properties}}
\DoxyCodeLine{00372\ }
\DoxyCodeLine{00373\ \ \ \ \ T\ min\_dist\ =\ 1e15;\ \textcolor{comment}{//\ Initialize\ minimum\ distance\ with\ a\ large\ value}}
\DoxyCodeLine{00374\ \ \ \ \ \textcolor{keywordtype}{unsigned}\ \textcolor{keywordtype}{int}\ vertex\_index\ =\ 0;\ \textcolor{comment}{//\ Vertex\ index\ where\ the\ collision\ occurred}}
\DoxyCodeLine{00375\ \ \ \ \ \textcolor{keywordtype}{bool}\ bounced\ =\ \textcolor{keyword}{false};\ \textcolor{comment}{//\ Flag\ indicating\ whether\ the\ ray\ has\ collided\ with\ a\ surface}}
\DoxyCodeLine{00376\ }
\DoxyCodeLine{00377\ \ \ \ \ \textcolor{comment}{//\ Loop\ through\ each\ vertex\ in\ the\ geometry\ to\ check\ for\ collisions}}
\DoxyCodeLine{00378\ \ \ \ \ \textcolor{keywordflow}{for}\ (\textcolor{keyword}{auto}\ i\ =\ 0;\ i\ <\ geometry.\mbox{\hyperlink{class_geometry_afd3955430cb19adbb9ea3797e5d1ec61}{get\_num\_vertices}}();\ i++)\ \{}
\DoxyCodeLine{00379\ \ \ \ \ \ \ \ \ \mbox{\hyperlink{class_matrix}{Matrix<T>}}\ p1(3,\ 1,\ \{p1\_x(i),\ p1\_y(i),\ p1\_z(i)\});}
\DoxyCodeLine{00380\ \ \ \ \ \ \ \ \ \mbox{\hyperlink{class_matrix}{Matrix<T>}}\ p2(3,\ 1,\ \{p2\_x(i),\ p2\_y(i),\ p2\_z(i)\});}
\DoxyCodeLine{00381\ \ \ \ \ \ \ \ \ \mbox{\hyperlink{class_matrix}{Matrix<T>}}\ p3(3,\ 1,\ \{p3\_x(i),\ p3\_y(i),\ p3\_z(i)\});}
\DoxyCodeLine{00382\ \ \ \ \ \ \ \ \ \mbox{\hyperlink{class_matrix}{Matrix<T>}}\ norm(3,\ 1,\ \{norm\_x(i),\ norm\_y(i),\ norm\_z(i)\});}
\DoxyCodeLine{00383\ \ \ \ \ \ \ \ \ \mbox{\hyperlink{class_matrix}{Matrix<T>}}\ pos(3,\ 1);}
\DoxyCodeLine{00384\ }
\DoxyCodeLine{00385\ \ \ \ \ \ \ \ \ T\ dist\ =\ 0.0;}
\DoxyCodeLine{00386\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{bool}\ collided\ =\ check\_vertex\_collision(p1,\ p2,\ p3,\ norm,\ pos,\ dist);\ \textcolor{comment}{//\ Check\ if\ the\ ray\ intersects\ the\ triangle}}
\DoxyCodeLine{00387\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (i\ !=\ spawn\_vertex\_index\ \&\&\ collided\ \&\&\ min\_dist\ >\ dist)\ \{}
\DoxyCodeLine{00388\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ Update\ the\ collision\ data\ if\ this\ collision\ is\ closer\ than\ previous\ ones}}
\DoxyCodeLine{00389\ \ \ \ \ \ \ \ \ \ \ \ \ p1\_col\ =\ p1;}
\DoxyCodeLine{00390\ \ \ \ \ \ \ \ \ \ \ \ \ p2\_col\ =\ p2;}
\DoxyCodeLine{00391\ \ \ \ \ \ \ \ \ \ \ \ \ p3\_col\ =\ p3;}
\DoxyCodeLine{00392\ \ \ \ \ \ \ \ \ \ \ \ \ norm\_col\ =\ norm;}
\DoxyCodeLine{00393\ \ \ \ \ \ \ \ \ \ \ \ \ pos\_col\ =\ pos;}
\DoxyCodeLine{00394\ \ \ \ \ \ \ \ \ \ \ \ \ vertex\_index\ =\ i;}
\DoxyCodeLine{00395\ \ \ \ \ \ \ \ \ \ \ \ \ min\_dist\ =\ dist;}
\DoxyCodeLine{00396\ \ \ \ \ \ \ \ \ \ \ \ \ bounced\ =\ \textcolor{keyword}{true};\ \textcolor{comment}{//\ Set\ the\ flag\ indicating\ a\ collision\ has\ occurred}}
\DoxyCodeLine{00397\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00398\ \ \ \ \ \}}
\DoxyCodeLine{00399\ }
\DoxyCodeLine{00400\ \ \ \ \ \textcolor{comment}{//\ If\ no\ collision\ occurred,\ return\ an\ empty\ vector\ (no\ child\ rays\ generated)}}
\DoxyCodeLine{00401\ \ \ \ \ \textcolor{keywordflow}{if}\ (!bounced)\ \textcolor{keywordflow}{return}\ children\_rays;}
\DoxyCodeLine{00402\ }
\DoxyCodeLine{00403\ \ \ \ \ \textcolor{comment}{//\ Compute\ the\ reflection\ directions\ after\ collision}}
\DoxyCodeLine{00404\ \ \ \ \ \mbox{\hyperlink{class_matrix}{Matrix<T>}}\ norm\_direction\ =\ norm\_col;}
\DoxyCodeLine{00405\ \ \ \ \ \mbox{\hyperlink{class_matrix}{Matrix<T>}}\ tan1\_direction\ =\ (velocity\ -\/\ norm\_direction\ *\ velocity.\mbox{\hyperlink{class_matrix_afcee4f858a2f7dfde3dc28e6d1d32c59}{tr}}().dot(norm\_direction)(0,\ 0))\ /\ (velocity\ -\/\ norm\_direction\ *\ velocity.\mbox{\hyperlink{class_matrix_afcee4f858a2f7dfde3dc28e6d1d32c59}{tr}}().dot(norm\_direction)(0,\ 0)).\mbox{\hyperlink{class_matrix_a7ef7109486e3ba18eced478f5cc568cc}{norm}}();}
\DoxyCodeLine{00406\ \ \ \ \ \mbox{\hyperlink{class_matrix}{Matrix<T>}}\ tan2\_direction\ =\ norm\_col.\mbox{\hyperlink{class_matrix_a03b588592a081b3bcba0e121ca0164b1}{cross}}(tan1\_direction);\ \textcolor{comment}{//\ Tangential\ direction\ orthogonal\ to\ the\ normal}}
\DoxyCodeLine{00407\ }
\DoxyCodeLine{00408\ \ \ \ \ \textcolor{comment}{//\ Compute\ the\ velocity\ components\ along\ the\ normal\ and\ tangential\ directions}}
\DoxyCodeLine{00409\ \ \ \ \ T\ vel\_in\_norm\ =\ (velocity.\mbox{\hyperlink{class_matrix_afcee4f858a2f7dfde3dc28e6d1d32c59}{tr}}().dot(norm\_direction))(0,\ 0);}
\DoxyCodeLine{00410\ \ \ \ \ T\ vel\_in\_tan1\ =\ (velocity.\mbox{\hyperlink{class_matrix_afcee4f858a2f7dfde3dc28e6d1d32c59}{tr}}().dot(tan1\_direction))(0,\ 0);}
\DoxyCodeLine{00411\ \ \ \ \ T\ vel\_in\_tan2\ =\ (velocity.\mbox{\hyperlink{class_matrix_afcee4f858a2f7dfde3dc28e6d1d32c59}{tr}}().dot(tan2\_direction))(0,\ 0);}
\DoxyCodeLine{00412\ }
\DoxyCodeLine{00413\ \ \ \ \ T\ vel\_in[4]\ =\ \{vel\_in\_tan1,\ vel\_in\_tan2,\ vel\_in\_norm\};\ \textcolor{comment}{//\ Store\ input\ velocities\ for\ kernel\ function}}
\DoxyCodeLine{00414\ \ \ \ \ }
\DoxyCodeLine{00415\ \ \ \ \ \textcolor{comment}{//\ Extract\ the\ GSI\ and\ surface\ properties\ at\ the\ point\ of\ collision}}
\DoxyCodeLine{00416\ \ \ \ \ \textcolor{keywordflow}{for}\ (\textcolor{keyword}{auto}\ i\ =\ 0;\ i\ <\ GSI\_properties.size();\ i++)\ \{}
\DoxyCodeLine{00417\ \ \ \ \ \ \ \ \ GSI\_prop\_col[i]\ =\ GSI\_properties[i](0,\ vertex\_index);}
\DoxyCodeLine{00418\ \ \ \ \ \}}
\DoxyCodeLine{00419\ }
\DoxyCodeLine{00420\ \ \ \ \ \textcolor{keywordflow}{for}\ (\textcolor{keyword}{auto}\ i\ =\ 0;\ i\ <\ surface\_properties.size();\ i++)\ \{}
\DoxyCodeLine{00421\ \ \ \ \ \ \ \ \ surface\_prop\_col[i]\ =\ surface\_properties[i](0,\ vertex\_index);}
\DoxyCodeLine{00422\ \ \ \ \ \}}
\DoxyCodeLine{00423\ }
\DoxyCodeLine{00424\ \ \ \ \ \textcolor{comment}{//\ Generate\ child\ rays\ after\ collision}}
\DoxyCodeLine{00425\ \ \ \ \ \textcolor{keywordflow}{for}\ (\textcolor{keyword}{auto}\ i\ =\ 0;\ i\ <\ children;\ i++)\ \{}
\DoxyCodeLine{00426\ \ \ \ \ \ \ \ \ T\ vel\_refl[4]\ =\ \{0.0,\ 0.0,\ 0.0\};\ \textcolor{comment}{//\ Reflected\ velocity\ components}}
\DoxyCodeLine{00427\ \ \ \ \ \ \ \ \ kernel(vel\_in,\ vel\_refl,\ GSI\_prop\_col,\ gas\_prop\_col,\ surface\_prop\_col);\ \textcolor{comment}{//\ Apply\ the\ kernel\ function\ to\ compute\ reflection}}
\DoxyCodeLine{00428\ }
\DoxyCodeLine{00429\ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ Compute\ the\ reflected\ velocity\ vector\ for\ the\ child\ ray}}
\DoxyCodeLine{00430\ \ \ \ \ \ \ \ \ \mbox{\hyperlink{class_matrix}{Matrix<T>}}\ child\_velocity(3,\ 1);}
\DoxyCodeLine{00431\ \ \ \ \ \ \ \ \ child\_velocity\ =\ norm\_direction\ *\ (-\/vel\_refl[2])\ *\ sgn<T>(vel\_in[2])\ +\ }
\DoxyCodeLine{00432\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ tan1\_direction\ *\ vel\_refl[0]\ +\ }
\DoxyCodeLine{00433\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ tan2\_direction\ *\ vel\_refl[1];}
\DoxyCodeLine{00434\ }
\DoxyCodeLine{00435\ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ Create\ the\ child\ ray\ and\ add\ it\ to\ the\ list\ of\ child\ rays}}
\DoxyCodeLine{00436\ \ \ \ \ \ \ \ \ \mbox{\hyperlink{class_ray}{Ray<T>}}\ child\_ray(pos\_col,\ child\_velocity,\ mass\_flux\ /\ children\ *\ velocity.\mbox{\hyperlink{class_matrix_a7ef7109486e3ba18eced478f5cc568cc}{norm}}()\ /\ child\_velocity.\mbox{\hyperlink{class_matrix_a7ef7109486e3ba18eced478f5cc568cc}{norm}}(),\ 1,\ vertex\_index);}
\DoxyCodeLine{00437\ \ \ \ \ \ \ \ \ children\_rays.push\_back(child\_ray);\ }
\DoxyCodeLine{00438\ \ \ \ \ \}}
\DoxyCodeLine{00439\ }
\DoxyCodeLine{00440\ \ \ \ \ \textcolor{comment}{//\ Store\ the\ index\ of\ the\ vertex\ where\ the\ collision\ occurred}}
\DoxyCodeLine{00441\ \ \ \ \ *collision\_index\ =\ vertex\_index;}
\DoxyCodeLine{00442\ }
\DoxyCodeLine{00443\ \ \ \ \ \textcolor{comment}{//\ Return\ the\ generated\ child\ rays}}
\DoxyCodeLine{00444\ \ \ \ \ \textcolor{keywordflow}{return}\ children\_rays;}
\DoxyCodeLine{00445\ \}}

\end{DoxyCode}
