This page contains codes of useful math methods already turned into code.

Geometry

Segments' intersection [1]

  1. PVector intersetion( PVector a1, PVector a2, PVector b1, PVector b2 ) {
  2. float a = a2.x - a1.x;
  3. float b = b1.x - b2.x;
  4. float c = a2.y - a1.y;
  5. float d = b1.y - b2.y;
  6. float e = b1.x - a1.x;
  7. float f = b1.y - a1.y;
  8. float denom = a * d - b * c;
  9. if ( abs( denom ) < 1e-5 ) {
  10. // parrallel
  11. return null;
  12. } else {
  13. float t = (e*d - b*f)/denom;
  14. return new PVector( a1.x + t * ( a2.x - a1.x ), a1.y + t * ( a2.y - a1.y ) );
  15. }
  16. }


Cite error: <ref> tags exist, but no <references/> tag was found

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]]