1 /***************************************************************************
2 ** Class: GLViewer_CoordSystem
5 ** Created: UI team, 03.09.02
6 ****************************************************************************/
8 //#include <GLViewerAfx.h>
9 #include "GLViewer_CoordSystem.h"
12 GLViewer_CoordSystem::GLViewer_CoordSystem( CSType aType, double X0, double Y0,
13 double XUnit, double YUnit, double Rotation )
17 setUnits( XUnit, YUnit );
18 setRotation( Rotation );
21 void GLViewer_CoordSystem::getOrigin( double& x, double& y ) const
27 void GLViewer_CoordSystem::setOrigin( double x, double y )
33 void GLViewer_CoordSystem::getUnits( double& x, double& y ) const
39 void GLViewer_CoordSystem::setUnits( double x, double y )
52 double GLViewer_CoordSystem::getRotation() const
57 void GLViewer_CoordSystem::setRotation( double rotation )
59 myRotation = rotation;
62 GLViewer_CoordSystem::CSType GLViewer_CoordSystem::getType() const
67 void GLViewer_CoordSystem::setType( CSType type )
72 void GLViewer_CoordSystem::toReference( double& x, double& y )
74 if( myType==Cartesian )
76 double newx = myX0 + myXUnit*x*cos(myRotation) - myYUnit*y*sin(myRotation),
77 newy = myY0 + myXUnit*x*sin(myRotation) + myYUnit*y*cos(myRotation);
81 else if( myType==Polar )
83 double r = x, phi = y;
84 x = myX0 + myXUnit*r*cos(phi+myRotation);
85 y = myY0 + myXUnit*r*sin(phi+myRotation);
89 void GLViewer_CoordSystem::fromReference( double& x, double& y )
91 x = (x - myX0) / myXUnit;
92 y = (y - myY0) / myYUnit;
94 if( myType==Cartesian )
96 double newx = x*cos(myRotation) + y*sin(myRotation),
97 newy = -x*sin(myRotation) + y*cos(myRotation);
101 else if( myType==Polar )
103 double r = sqrt( x*x+y*y );
105 double eps = 1E-8, pi = 3.14159265;
112 if( x<0 ) // 2-nd or 4-rd quarter
125 void GLViewer_CoordSystem::transform( GLViewer_CoordSystem& aSystem, double& x, double& y )
128 aSystem.fromReference( x, y );
131 void GLViewer_CoordSystem::getStretching( GLViewer_CoordSystem& aSystem, double& theX, double& theY )
133 theX = myXUnit / aSystem.myXUnit;
134 theY = myYUnit / aSystem.myYUnit;