diff --git a/src/frameworks/UBGeometryUtils.cpp b/src/frameworks/UBGeometryUtils.cpp index eb36a27e..cd6ff7ef 100644 --- a/src/frameworks/UBGeometryUtils.cpp +++ b/src/frameworks/UBGeometryUtils.cpp @@ -255,8 +255,6 @@ QPolygonF UBGeometryUtils::arcToPolygon(const QLineF& startRadius, qreal spanAng */ QPolygonF UBGeometryUtils::curveToPolygon(const QList& points, qreal startWidth, qreal endWidth) { - typedef QPair pointPair; - int n_points = points.size(); if (n_points < 2) @@ -431,7 +429,18 @@ void UBGeometryUtils::crashPointList(QVector &points) /** * @brief Return the angle between three points */ -qreal UBGeometryUtils::angle(const QPointF& a, const QPointF& b, const QPointF& c) +qreal UBGeometryUtils::angle(const QPointF& p1, const QPointF& p2, const QPointF& p3) { - return (QLineF(a, b).angle() - QLineF(b, c).angle()); + // Angle between three points, using the law of cosines: + // The angle at B equals arccos((a^2-b^2-c^2)/(2*a*c)), where a, b and c are the sides of the triangle + // opposite A, B and C, respectively + + qreal a, b, c, beta; + a = qSqrt(qPow(p2.x() - p3.x(), 2) + qPow(p2.y() - p3.y(), 2)); + b = qSqrt(qPow(p1.x() - p3.x(), 2) + qPow(p1.y() - p3.y(), 2)); + c = qSqrt(qPow(p1.x() - p2.x(), 2) + qPow(p1.y() - p2.y(), 2)); + + beta = qAcos((a*a - b*b - c*c)/(2*a*c)); + + return 2*3.14159*beta; } diff --git a/src/frameworks/UBGeometryUtils.h b/src/frameworks/UBGeometryUtils.h index 988b4a20..f4174709 100644 --- a/src/frameworks/UBGeometryUtils.h +++ b/src/frameworks/UBGeometryUtils.h @@ -55,7 +55,7 @@ class UBGeometryUtils static void crashPointList(QVector &points); - static qreal angle(const QPointF& a, const QPointF& b, const QPointF& c); + static qreal angle(const QPointF& p1, const QPointF& p2, const QPointF& p3); const static int centimeterGraduationHeight; const static int halfCentimeterGraduationHeight;