File indexing completed on 2024-04-21 03:40:38

0001 /*************************************************************************************
0002  *  Copyright (C) 2007-2009 by Aleix Pol <aleixpol@kde.org>                          *
0003  *  Copyright (C) 2010-2013 by Percy Camilo T. Aucahuasi <percy.camilo.ta@gmail.com> *
0004  *                                                                                   *
0005  *  This program is free software; you can redistribute it and/or                    *
0006  *  modify it under the terms of the GNU General Public License                      *
0007  *  as published by the Free Software Foundation; either version 2                   *
0008  *  of the License, or (at your option) any later version.                           *
0009  *                                                                                   *
0010  *  This program is distributed in the hope that it will be useful,                  *
0011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of                   *
0012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                    *
0013  *  GNU General Public License for more details.                                     *
0014  *                                                                                   *
0015  *  You should have received a copy of the GNU General Public License                *
0016  *  along with this program; if not, write to the Free Software                      *
0017  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA   *
0018  *************************************************************************************/
0019 
0020 #ifndef MATHUTILS_H
0021 #define MATHUTILS_H
0022 
0023 #include <QLineF>
0024 #include <QPair>
0025 #include <QVector3D>
0026 
0027 double radiansToDegrees(double rad);
0028 
0029 double radiansToGradians(double rad);
0030 
0031 QPointF polarToCartesian(double radial, double polar);
0032 
0033 void cartesianToPolar(double x, double y, double &radial, double &polar);
0034 
0035 QVector3D cylindricalToCartesian(double radial, double polar, double height);
0036 
0037 QVector3D sphericalToCartesian(double radial, double azimuth, double polar);
0038 
0039 bool isSimilar(double a, double b, double diff = .0000001);
0040 
0041 bool oppositeSign(double a, double b);
0042 
0043 bool inInterval(double val, double from, double to);
0044 
0045 bool traverse(double p1, double p2, double next);
0046 
0047 QLineF slopeToLine(const double &der);
0048 
0049 QLineF mirrorXY(const QLineF& l);
0050 
0051 // greatest common divisor of two nonnegative integers (Binary GCD algorithm, iterative version, source: Wikipedia Dec. 2013)
0052 unsigned int gcd(unsigned int u, unsigned int v);
0053 
0054 QPair<unsigned int, unsigned int> simplifyFraction(unsigned int n, unsigned int d);
0055 
0056 #endif