diff --git a/poly2d/p2d_attrib.c b/poly2d/p2d_attrib.c index 406240b..87a476b 100644 --- a/poly2d/p2d_attrib.c +++ b/poly2d/p2d_attrib.c @@ -28,19 +28,23 @@ static double angle_3(const struct v2d *a, const struct v2d *b, { double ax, ay, bx, by; double aa, bb; - double angle; + double cross, angle; ax = b->x - a->x; ay = b->y - a->y; bx = c->x - b->x; by = c->y - b->y; + cross = ax * by - ay * bx; + if (!cross) + return 0; + aa = hypot(ax, ay); bb = hypot(bx, by); angle = acos((ax * bx + ay * by) / aa / bb) / M_PI * 180.0; - return ax * by - ay * bx >= 0 ? angle : -angle; + return cross >= 0 ? angle : -angle; } /*