File indexing completed on 2025-01-19 03:51:13
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2005-01-18 0007 * Description : triangle geometry calculation class. 0008 * 0009 * SPDX-FileCopyrightText: 2005-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0010 * 0011 * SPDX-License-Identifier: GPL-2.0-or-later 0012 * 0013 * ============================================================ */ 0014 0015 #define RADIAN2DEGREE(a) (a * 57.295779513082) 0016 0017 #include "perspectivetriangle.h" 0018 0019 // C++ includes 0020 0021 #include <cstdio> 0022 #include <cstdlib> 0023 #include <cmath> 0024 0025 namespace DigikamEditorPerspectiveToolPlugin 0026 { 0027 0028 PerspectiveTriangle::PerspectiveTriangle(const QPoint& A, const QPoint& B, const QPoint& C) 0029 { 0030 m_a = distanceP2P(B, C); 0031 m_b = distanceP2P(A, C); 0032 m_c = distanceP2P(A, B); 0033 } 0034 0035 float PerspectiveTriangle::angleABC() const 0036 { 0037 return ( RADIAN2DEGREE( acos( (m_b*m_b - m_a*m_a - m_c*m_c ) / (-2*m_a*m_c ) ) ) ); 0038 } 0039 0040 float PerspectiveTriangle::angleACB() const 0041 { 0042 return ( RADIAN2DEGREE( acos( (m_c*m_c - m_a*m_a - m_b*m_b ) / (-2*m_a*m_b ) ) ) ); 0043 } 0044 0045 float PerspectiveTriangle::angleBAC() const 0046 { 0047 return ( RADIAN2DEGREE( acos( (m_a*m_a - m_b*m_b - m_c*m_c ) / (-2*m_b*m_c ) ) ) ); 0048 } 0049 0050 float PerspectiveTriangle::distanceP2P(const QPoint& p1, const QPoint& p2) const 0051 { 0052 return (sqrt( abs( p2.x()-p1.x() ) * abs( p2.x()-p1.x() ) + 0053 abs( p2.y()-p1.y() ) * abs( p2.y()-p1.y() ) )); 0054 } 0055 0056 } // namespace DigikamEditorPerspectiveToolPlugin