Skip to content

Instantly share code, notes, and snippets.

@AndrewTheTM
Created November 20, 2012 14:06
Show Gist options
  • Save AndrewTheTM/4118141 to your computer and use it in GitHub Desktop.
Save AndrewTheTM/4118141 to your computer and use it in GitHub Desktop.
Law of Cosines
//Law of cosines - cos angle = ((Ladj side 1)^2+(Ladj side 2)^2-(Lopposite)^2) / (2(Ladj side 1)(Ladj side 2))
double LAdj1=0;
double LAdj2=0;
double LOpp=0;
LAdj1=Math.sqrt(Math.pow(B.getX()-A.getX(),2)+Math.pow(B.getY()-A.getY(),2));
LAdj2=Math.sqrt(Math.pow(C.getX()-B.getX(),2)+Math.pow(C.getY()-B.getY(),2));
LOpp=Math.sqrt(Math.pow(C.getX()-A.getX(),2)+Math.pow(C.getY()-A.getY(),2));
theta=Math.acos((Math.pow(LAdj1, 2)+Math.pow(LAdj2, 2)-Math.pow(LOpp, 2))/(2*LAdj1*LAdj2));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment