Created
May 7, 2011 13:37
-
-
Save markessien/960501 to your computer and use it in GitHub Desktop.
Quad Function
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
public double angleWith(Edge otherEdge) { | |
double angle1 = Math.atan2(getPoint1().getY() - getPoint2().getY(), | |
getPoint1().getX() - getPoint2().getX()); | |
double angle2 = Math.atan2(otherEdge.getPoint1().getY() - otherEdge.getPoint2().getY(), | |
otherEdge.getPoint1().getX() - otherEdge.getPoint2().getX()); | |
double resultRadians = angle1 - angle2; | |
double resultDegrees = resultRadians * (180 / Math.PI); | |
if (resultDegrees < 0) | |
resultDegrees = 360 + resultDegrees; | |
return resultDegrees; | |
} | |
public static boolean quadIsConvex(Triangle t1, Triangle t2, Edge sharedEdge) { | |
if (t1 == t2) | |
return false; | |
Edge leftTopLine = t1.getEdge(2, sharedEdge); | |
Edge leftBottomLine = t1.getEdge(3, sharedEdge); | |
Edge rightTopLine = t2.getEdge(2, sharedEdge); | |
Edge rightBottomLine = t2.getEdge(3, sharedEdge); | |
double angle1 = leftTopLine.angleWith(leftBottomLine); | |
if (angle1 < 180) return false; | |
double angle = leftTopLine.angleWith(rightTopLine); | |
if (angle < 180) return false; | |
angle = rightTopLine.angleWith(rightBottomLine); | |
if (angle < 180) return false; | |
angle = rightBottomLine.angleWith(leftBottomLine); | |
if (angle < 180) return false; | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment