Allegro.cc Forums » Programming Questions » Determining if an angle causes polygon to be concave.

Credits go to hazul and Indeterminatus for helping out!
 Elverion Member #6,239 September 2005 I was thinking...if I can find the two angles using atan2, then subtract that from 360, it should give the angle at B, right? Or maybe my logic here is flawed.The math I'm using is: ``` float angle1 = fixtof( fixatan2(itofix(poly[c].y - poly.y), itofix(poly[c].x - poly.x)) ); float angle2 = fixtof( fixatan2(itofix(poly[a].y - poly.y), itofix(poly[a].x - poly.x)) ); float angleb = 360 - abs(angle1) - abs(angle2); allegro_message("Angle1 is: %f\nAngle2 is: %f\nAngle B must be: %f", angle1, angle2, angleb); ``` angle1 and angle2 are occasionally negative...is that correct? To compensate for that, I just used their absolute values in finding angleb. My problem here now is that angleb is almost always > 200.0, which can't be correct. What am I doing wrong?So then I was thinking, instead of subtracting from 360, and checking if it's > 180, to subtract from 180, and check if it's greater than 90. The numbers looked right...but the graph didn't. --SolarStrike Software - MicroMacro home - Automation software.
 Elverion Member #6,239 September 2005 Quote: Hmm.. why use this:...instead of this ? 163 C:\poly_test\c_poly.cpp conversion from `int' to non-scalar type `fix' requested Already tried it.It has occured to me that fixatan2 uses "Allegro degrees", right? I've modified my code to: ``` float angle1 = fixtof( fixatan2(itofix(poly[c].y - poly.y), itofix(poly[c].x - poly.x)) ); float angle2 = fixtof( fixatan2(itofix(poly[a].y - poly.y), itofix(poly[a].x - poly.x)) ); float angleb = 256 - abs( ((128-angle1) - (256-angle2)) ); if ( (angleb < 0) || (angleb > 192) ) return false; ``` Everything seems to be in order now, so long as points are NOT entered in a clockwise fashion. I'll have to keep testing polygon after polygon to make sure that everything is in order.Even though you may not have given me the perfect answer, I always look forward to your feedback, and your replies made me think down the right path. So, cookies to you both. --SolarStrike Software - MicroMacro home - Automation software.