moller-trumber intersection algoritam

trikonamulla thalam samavaakyathinte munkootty kanakkukoottal aavasyamillaathe oru kiranatthinteyum trikonathinteyum vibhajanam moonnu alavukalil kanakkakkunnathinulla oru drutha reethiyaanu athinte kandupiduthakkaraya tomas mollerinteyum benn trumberinteyum peril peritta mullar-trumber reey-triangle intersection algoritam. mattu upayogangalkoppam, trikona meshukal ulppedunna reey tracing kanakkukoottalukal nadappilakkaan computer graphixil ithu upayogikkaam.
kanakkukoottal.
nirvachanangal.
oru orijin pooyint formula oru direction vekttar formula _ 2 aanu kiranatthe nirvachikkunnath.
kiranatthile oro binduvum formula 3 upayogichu prakadippikkaan kazhiyum, avide paaraameettar formula 4 poojyathil ninnu anantatha vare vyathyaasappedunnu.
formula _ 5, formula _ 6, formula _ 7 enningane moonnu konukalaal trikonathe nirvachikkunnu.
tribhujam ulla thalathe, reey-triangle intersection kanakkakkaan aavashyamaaya, nirvachikkunnath samathalathile oru poyintaanu, athaayath formula _ 5, aaa thalatthile oro pooyintinum oorthoogoonal aaya oru vekttar, formula _ 5 muthal formula _ 6 vareyulla vekttarum formula _ 5 muthal formula _ 7 vareyulla vekttarum thammilulla cross prodaktta
formula _ 13, ivide formula _ 14, formula _ 15, formula _ 16 enniva prathalatthile eathenkilum poyintukalaanu.
tribhujathinu samaantharamaayi kiranamundo ennu parisodhikkuka.
aadyam, tribhujam ulla thalavumaayi kiranam murichukadakkunnundo ennu kandethuka, angane cheythaal, aaa vibhajanathinte kordinettukal kandethuka. kiranatthinte disha vekttar thalathinu samaantharamaanengil maathrame kiranatthinte thalathe murichukadakkaan kazhiyoo. ithu sambhavikkumbol, kiranatthinte dishasoochana thalatthinte saadhaaranadishaasoochanayum thammilulla dott prodakt poojyamaayirikkum. allaathapaksham, reey evideyengilum thalam murichukadakkunnu, pakshe trikonathinullil aayirikkanamennilla.
tribhujathinu puratthaano reey-playin intersection ennu parisodhikkuka.
barrisentric kordinettukal upayogichu, trikonathile eathu binduvum trikonatthinte konangalude convex kombineshanaayi prakadippikkaan kazhiyum 
soothravaakyam _ 17
gunakangal negatteevu allaathathum 1 enna thukayum aayirikkanam, athinaal W-neey formula _ 18 upayogichu maattisthaapikkaam
formula _ 19, ivide formula _ 20 ennathu thalatthile eathenkilum poyintaanu.
soothravaakyam _ 21 umm soothravaakyam _ 22 umm trikonatthinte arikilulla vektarukalaanennum avaa orumichu oru thalam (uthbhavathiloode kadannupokunna) vyaapippikkunnuvennum nireekshikkuka. aaa thalatthile oro pooyintum formula _ 23 aayi ezhuthaam, koodaathe aaa pooyint trikonathilulla thalatthilekku "neekkaan" formula _ 5 upayogichu vivarthanam cheyyaam.
oru prathyeka intersectionte formula _ 25 umm formula _ 26 umm kandethaan, reey expression playin expression thulyamaayi sajjeekarikkuka, koodaathe variableukal oru vashathum sthiraangangal maruvashathum vaykkuka.
soothravaakyam _ 27
moonnu samavaakyangalum (formula _ 28, formula _ 29, formula _ 30 ennivaykku oronnum) moonnu anjjaathangalum (formula _ 4, formula _ 25, formula _ 26) ulla oru rekheeya samavaakyangalude samvidaanamaanithu, ithu oru matricks-vector gunanamaayi prathinidheekarikkam.
soothravaakyam _ 34
matrixinu formula _ 35 ll moonnu leanierly indipendant koolam vektarukal ullappol eee samavaakyathin ellaayppozhum oru pariharam undaakum, athinaal ithu invertable aayirikkum. trikonatthinte konukal collinear allaathathum reey plaininu samaantharamallathathum aanenkil maathrame ithu sambhavikkoo.
oru intersectionte formula _ 4, formula _ 25, formula _ 26 moolyangal kandethaan algoritam kraamarinte niyamam upayogikkaam, athu trikonathinullil aanenkil, reyude samavaakyathilekku formula _ 4 plug inn cheythukondu intersectionte krithyamaaya kordinettukal kandethanakum.
sii + + nadappaakkal.
sii + + leeii algoritam nadappaakkunnathu thaazhepparayunnavayaanu
boole raintersectstriyaangtriyaa raintersectstriyaangtriyaa reyorijin, 
 puthiya raivaktar, 
 trikona * antarbhuja,
 antarbhuja & outtu intersection pooyint)
 koonst float epsiloon = 0.0000001;
 puthiya vertex 0 = intriyaankil-> vertex 0;
 puthiya vekttar3dii = intriyaankil-> intriyaankil-> 
 puthiya vekttar3dii = intriyaankil-> vekttar3dii;
 puthiya vekttar3dii, vekttar3dii, echu, ezz, kyu;
 float a, f, u, v;
 edju 1 = vertex 1-vertex 0;
 edju 2 = vertex 2-vertex 0;
 h = raivaktar.cross prodakt (edju 2);
 a = edge1.dotproduct (h);
 (a>-epsiloon & & a <epsiloon)
 thettaaya thirichuvaravu;// eee kiranam eee trikonathinu samaantharamaanu.
 f = 1/a;
 s = reyorijin-vertex 0;
 yuu = eph * ezz.dott prodakt (echu);
 (yuu <0.0) aanenkil || yuu> 1)
 vyaajamaayi thirike nalkuka;
 q = s.cross prodakt (edju 1);
 v = f * raivaktar.dott prodakt (q);
 (v <0.0) || yuu + vii> 1)
 vyaajamaayi thirike nalkuka;
 //eee ghattathil namukk tii kanakkukoottaam, intersection pooyint lainil evideyaanennu kandethaam.
 float tii = eph * edge2.dotproduct (kyu);
 (tii> epsiloon)// reey intersection aanenkil
 auttimttarsekshanpoyint = reyorijin + raivaktar * tii;
 sharee thirichuvaravu;
 allengil// ithinartham oru line intersection undengilum oru reey intersection illa ennaanu.
 vyaajamaayi thirike nalkuka;
jaava nadappaakkal.
jaava 3 dii apiyil ninnu kokvi _ 1 upayogichu jaavayile algoritam nadappilaakkunnathu inipparayunnavayaanu
public klaas mollertrumbur {
 swakaarya staatik final double epsiloon = 0.0000001;
 public staatik booliyan raintersectriyaamgil (pooyint pooyint reyorijin, 
 puthiya raivaktar,
 trikonaanthareeksham,
 pooyint pooyint outersection pooyint) {
 pooyint pooyint vertex 0 = intriyaankil.getwertex 0 ();
 pooyint pooyint vertex 1 = intriyaankil.getwertex 1 ();
 pooyint pooyint vertex 2 = intriyaankil.getwertex 2 ();
 puthiya vekttar3dii = puthiya puthiya ();
 puthiya vekttar3dii = puthiya puthiya ();
 (); = puthiya puthiya ();
 puthiya ezz = puthiya puthiya ();
 puthiya q = puthiya puthiya ();
 eratta a, f, u, v;
 edge1.sub (sheershakam 1, sheershakam 0);
 edge2.sub (sheershakam 2, sheershakam 0);
 echu.cross (raivaktar, edju 2);
 a = edge1.dot (h);
 (a>-epsiloon & & a <epsiloon) {
 thettaaya thirichuvaravu;// eee kiranam eee trikonathinu samaantharamaanu.
 f = 1/a;
 ezz.sub (reyorijin, vertex 0);
 yuu = eph * (ezz.dott (echu));
 (yuu <0.0) aanenkil || yuu> 1) {
 vyaajamaayi thirike nalkuka;
 kyu.cross (kall, edju 1);
 v = f * raivaktar.dott (q);
 (v <0.0) || yuu + vii> 1) {
 vyaajamaayi thirike nalkuka;
 //eee ghattathil namukk tii kanakkukoottaam, intersection pooyint lainil evideyaanennu kandethaam.
 eratta t = f * edge2.dot (q);
 (tii> epsiloon)// reey intersection aanenkil
 auttimttarsekshan pooyint.settu (0.0,0,0);
 auttimttarsekshan pooyint.skaylad (tii, raivaktar, reorijin);
 sharee thirichuvaravu;
 } allengil// ithinartham oru line intersection undengilum oru reey intersection illa ennaanu.
 vyaajamaayi thirike nalkuka;

