Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.36 KB | None | 0 0
  1. var AC = sqrt((ax-x)^2 + (ay-y)^2)
  2. var BC = sqrt((bx-x)^2 + (by-y)^2)
  3. var AB = sqrt((ax-bx)^2 + (ay-by)^2)
  4. var CH = abs((ay-by)*x - (ax - bx)*y + ax*by - bx*ay)/AB
  5. var cosCAB = ((ax-x)*(ax - bx) + (ay - y)*(ay - by))/(AC*BC)
  6. var cosCBA = ((bx-x)*(bx - ax) + (by - y)*(by - ay))/(AB*BC)
  7. if (cosCAB < 0) { return AC}
  8. else if (cosCBA < 0) {return BC}
  9. else {return CH}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement