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