Skip to content

Instantly share code, notes, and snippets.

@hueitan

hueitan/three_points.md

Last active Aug 29, 2015
Embed
What would you like to do?
N = _fArgs[0]

P1 = N[0]
P2 = N[1]
P3 = N[2]

// area - check http://www.gottfriedville.net/mathtools/triarea.html
Area = Math.abs((P1[0]*(P2[1]-P3[1]) + P2[0]*(P3[1]-P1[1]) + P3[0]*(P1[1]-P2[1]))/2)

if (Area != 0) {
  return Area | 0
}

// length
X1 = Math.sqrt(Math.pow((P1[0]-P2[0]),2) + Math.pow((P1[1]-P2[1]),2)) | 0
X2 = Math.sqrt(Math.pow((P1[0]-P3[0]),2) + Math.pow((P1[1]-P3[1]),2)) | 0
X3 = Math.sqrt(Math.pow((P2[0]-P3[0]),2) + Math.pow((P2[1]-P3[1]),2)) | 0

return Math.max(X1,X2,X3)

2 points distance - check http://stackoverflow.com/a/20916980/1748884

var d = Math.sqrt( (x2-=x1)*x2 + (y2-=y1)*y2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.