MCPcopy Create free account
hub / github.com/OpenBoard-org/OpenBoard / angle

Method angle

src/frameworks/UBGeometryUtils.cpp:423–441  ·  view source on GitHub ↗

* @brief Return the angle in degrees between three points */

Source from the content-addressed store, hash-verified

421 * @brief Return the angle in degrees between three points
422 */
423qreal UBGeometryUtils::angle(const QPointF& p1, const QPointF& p2, const QPointF& p3)
424{
425 // Angle between three points, using the law of cosines:
426 // 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
427 // opposite A, B and C, respectively
428
429 qreal a, b, c, beta;
430 a = qSqrt(qPow(p2.x() - p3.x(), 2) + qPow(p2.y() - p3.y(), 2));
431 b = qSqrt(qPow(p1.x() - p3.x(), 2) + qPow(p1.y() - p3.y(), 2));
432 c = qSqrt(qPow(p1.x() - p2.x(), 2) + qPow(p1.y() - p2.y(), 2));
433
434 if (a == 0 || c == 0)
435 beta = 3.14159;
436 else
437 beta = qAcos(std::max(-1.0, std::min(1.0, (a*a - b*b + c*c)/(2*a*c))));
438
439
440 return 180.* beta/3.14159;
441}
442
443
444

Callers 9

protractorToSvgMethod · 0.45
handleItemMouseMoveMethod · 0.45
lineToPolygonMethod · 0.45
arcToPolygonMethod · 0.45
curveToPolygonMethod · 0.45
inputDeviceMoveMethod · 0.45
initializeTransformMethod · 0.45
mouseMoveEventMethod · 0.45
positionHandlesMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected