Transform2D.h

Go to the documentation of this file.
00001 // 
00002 //   Copyright (C) 2003-2006 Rational Discovery LLC
00003 //
00004 //   @@ All Rights Reserved  @@
00005 //
00006 #ifndef __RD_TRANSFORM2D_H__
00007 #define __RD_TRANSFORM2D_H__
00008 
00009 #include "Transform.h"
00010 #include <Numerics/SquareMatrix.h>
00011 
00012 namespace RDGeom {
00013   class Point2D;
00014   const unsigned int DIM_2D=3;
00015 
00016   class Transform2D : public RDNumeric::SquareMatrix<double> {
00017   public:
00018     //! \brief Constructor
00019     /*!  
00020       Initialize to an identity matrix transformation
00021       This is a 3x3 matrix that includes the rotation and translation parts
00022       see Foley's "Introduction to Computer Graphics" for the representation
00023 
00024       Operator *= and = are provided by the parent class square matrix. 
00025       Operator *= needs some explanation, since the order matters. This transform gets set to
00026       the combination other and the current state of this transform
00027       If this_old and this_new are the states of this object before and after this function
00028       we have
00029               this_new(point) = this_old(other(point))
00030     */
00031     Transform2D() : RDNumeric::SquareMatrix<double>(DIM_2D,0.0) {
00032       unsigned int i, id;
00033       for (i = 0; i < DIM_2D; i++) {
00034         id = i*(DIM_2D+1);
00035         d_data[id] = 1.0;
00036       }
00037     }
00038 
00039     void setToIdentity();
00040 
00041     void TransformPoint(Point2D &pt) const;
00042 
00043     void SetTranslation(const Point2D &pt);
00044  
00045     /*! \brief Set the tranform so that the specified points are aligned
00046      *
00047      * The resulting tranformation will align pt1 with ref1, and rotation
00048      * pt2 such that the line betweem (pt1, pt2) will align with 
00049      * with the line (ref1, ref2)
00050      */
00051     void SetTransform(const Point2D &ref1, const Point2D &ref2,
00052                       const Point2D &pt1, const Point2D &pt2);
00053 
00054     /*! \brief Set the trans form to counterclock wise rotation by the specified value around point
00055      *
00056      * ARGUMENTS:
00057      *   - pt : point about which to rotate
00058      *   - angle : the angle byt which to rotate
00059      */
00060     void SetTransform(const Point2D &pt, double angle);
00061 
00062   private:
00063         
00064   };
00065 }
00066 
00067 /*! \brief Combine two transforms and return the results as a new transform
00068  *
00069  * The order is important here, on two transforms t1 and t2
00070  * t3 = t1*t2 
00071  * The resulting transform t3 has the folliwng effect
00072  *  t3(point) = t1(t2(point))
00073  */
00074 RDGeom::Transform2D operator* (const RDGeom::Transform2D &t1, const RDGeom::Transform2D &t2);
00075 
00076 
00077 #endif
00078 

Generated on Tue Oct 7 06:10:11 2008 for RDCode by  doxygen 1.5.5