Skip to content

Instantly share code, notes, and snippets.

@ikekou
Last active December 17, 2015 05:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ikekou/5559092 to your computer and use it in GitHub Desktop.
Save ikekou/5559092 to your computer and use it in GitHub Desktop.
[Math][JavaScript][CoffeeScript]各々2点を通る直線2本の交点を求める(参考:http://mf-atelier.sakura.ne.jp/mf-atelier/modules/tips/index.php/program/algorithm/a1.html
cross=(x1,y1,x2,y2,x3,y3,x4,y4)->
ksi = (y4 - y3) * (x4 - x1) - (x4 - x3) * (y4 - y1)
delta = (x2 - x1) * (y4 - y3) - (y2 - y1) * (x4 - x3)
ramda = ksi / delta
x = x1 + ramda * (x2 - x1)
y = y1 + ramda * (y2 - y1)
return [x,y]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment