Created
October 16, 2013 22:38
-
-
Save fiskurgit/7016208 to your computer and use it in GitHub Desktop.
Useful algebra funtions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int getTriangleArea(Triangle t){ | |
int v1 = distance(t.p1.x, t.p1.y, t.p2.x, t.p2.y); | |
int v2 = distance(t.p2.x, t.p2.y, t.p3.x, t.p3.y); | |
int v3 = distance(t.p3.x, t.p3.y, t.p1.x, t.p1.y); | |
int s = (v1 + v2 + v3) / 2; | |
return (int) sqrt(s * (s - v1) * (s - v2) * (s - v3)); | |
} | |
int distance(float x1, float y1, float x2, float y2){ | |
return (int) Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); | |
} | |
//http://en.wikipedia.org/wiki/Solution_of_triangles#Three_sides_given_.28SSS.29 | |
boolean isAcute(Triangle t){ | |
int v1 = distance(t.p1.x, t.p1.y, t.p2.x, t.p2.y); | |
int v2 = distance(t.p2.x, t.p2.y, t.p3.x, t.p3.y); | |
int v3 = distance(t.p3.x, t.p3.y, t.p1.x, t.p1.y); | |
double aA = acos((v2*v2 + v3*v3 - v1*v1) / (2.0*v2*v3)) * (180.0 / PI); | |
double aB = acos((v1*v1 + v3*v3 - v2*v2) / (2.0*v1*v3)) * (180.0 / PI); | |
double aC = (180.0 - aA - aB); | |
if(aA < 90 && aB < 90 && aC < 90){ | |
return true; | |
}else{ | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment