Skip to content

Instantly share code, notes, and snippets.

@markessien
Created May 7, 2011 13:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markessien/960501 to your computer and use it in GitHub Desktop.
Save markessien/960501 to your computer and use it in GitHub Desktop.
Quad Function
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