From: Darius S. <dst...@us...> - 2001-07-24 11:26:47
|
Update of /cvsroot/kuml/kuml/kuml_gui/src/ige/common In directory usw-pr-cvs1:/tmp/cvs-serv13849 Added Files: MathUtility.h MathUtility.cpp Log Message: Added file --- NEW FILE --- /* Generated by Together */ #ifndef MATHUTILITY_H #define MATHUTILITY_H class QPoint; /** * The utility class provides some needed math/geometric function. * All functions are static and may be used without creating an instance of this class. * @stereotype Utility */ class MathUtility { public: /** * The result we be stored in the variable r und fi */ static void convertKartToPolar(int x, int y, double& r, double& fi); /** * The result we be stored in the variable r und fi */ static void convertKartToPolar(const QPoint& start, const QPoint& end, double & r, double & fi); /** * The result we be stored in the variable x und y */ static void convertPolarToKart(double r, double fi, int& x, int& y); // static void convertPolarToKartAbs(double r, double fi, int& x, int& y); /** * Return degree between two points from 0 (0) to 2PI (360). * Right -- :0 (2PI) * Up := PI/2 * Left := PI * Down := PI + PI/2 */ static double getDegree(const QPoint & p1, const QPoint & p2); }; #endif //MATHUTILITY_H --- NEW FILE --- /* Generated by Together */ #include "MathUtility.h" #include <qpoint.h> #include <math.h> #include <stdlib.h> double MathUtility::getDegree(const QPoint & p1, const QPoint & p2){ double alpha; double fi; double deltaX; double deltaY; int x1 = p1.x(); int y1 = p1.y(); int x2 = p2.x(); int y2 = p2.y(); deltaX = abs(x1 - x2); deltaY = abs(y1 - y2); // First quadrant if((x1 < x2) && (y1 >= y2)) { fi = atan(deltaY/deltaX); } // Second quadrant if((x1 >= x2) && (y1 > y2)) { alpha = M_PI; fi = alpha - atan(deltaY/deltaX); } // Third quadrant if((x1 > x2) && (y1 <= y2)) { alpha = M_PI; fi = alpha + atan(deltaY/deltaX); } // Forth quadrant if((x1 <= x2) && (y1 < y2)) { alpha = M_PI + M_PI; fi = alpha - atan(deltaY/deltaX); } return fi; } /*void MathUtility::convertPolarToKartAbs(double r, double fi, int& x, int& y){ x = getStartPoint().x(); y = getStartPoint().y(); x += int(r * cos(fi)); y -= int(r * sin(fi)); }*/ void MathUtility::convertPolarToKart(double r, double fi, int& x, int& y){ x = int(r * cos(fi)); y = int(r * sin(fi)); } void MathUtility::convertKartToPolar(const QPoint& start, const QPoint& end, double & r, double & fi){ int x1 = start.x(); int y1 = start.y(); int x2 = end.x(); int y2 = end.y(); int deltaX = abs(x1 - x2); int deltaY = abs(y1 - y2); r = sqrt((deltaX*deltaX) + (deltaY*deltaY)); fi = getDegree(start, end); } void MathUtility::convertKartToPolar(int x, int y, double& r, double& fi){ r = sqrt((x*x) + (y*y)); QPoint p1(0,0); QPoint p2(x,y); fi = getDegree(p1, p2); } |