Frankiezafe (Talk | contribs) (→Segments' intersection Adapted from a stackoverflow post, by ubuntu - stackoverflow.com) |
Frankiezafe (Talk | contribs) |
||
| Line 22: | Line 22: | ||
} | } | ||
} | } | ||
| + | |||
| + | |||
| + | <references/> | ||
This page contains codes of useful math methods already turned into code.
PVector intersetion( PVector a1, PVector a2, PVector b1, PVector b2 ) {
float a = a2.x - a1.x;
float b = b1.x - b2.x;
float c = a2.y - a1.y;
float d = b1.y - b2.y;
float e = b1.x - a1.x;
float f = b1.y - a1.y;
float denom = a * d - b * c;
if ( abs( denom ) < 1e-5 ) {
// parrallel
return null;
} else {
float t = (e*d - b*f)/denom;
return new PVector( a1.x + t * ( a2.x - a1.x ), a1.y + t * ( a2.y - a1.y ) );
}
}
online identity ∋ [ social ∋ [mastodon♥, twitter®, facebook®, diaspora, linkedin®]
∥ repos ∋ [github®, gitlab♥, bitbucket®, sourceforge] ∥ media ∋ [itch.io®, vimeo®, peertube♥, twitch.tv®, tumblr®] ∥ communities ∋ [godotengine♥, openprocessing, stackoverflow, threejs]]