Base/Placement.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) 2006 Juergen Riegel                                     *
00003  *                                                                         *
00004  *   This file is part of the FreeCAD CAx development system.              *
00005  *                                                                         *
00006  *   This library is free software; you can redistribute it and/or         *
00007  *   modify it under the terms of the GNU Library General Public           *
00008  *   License as published by the Free Software Foundation; either          *
00009  *   version 2 of the License, or (at your option) any later version.      *
00010  *                                                                         *
00011  *   This library  is distributed in the hope that it will be useful,      *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00014  *   GNU Library General Public License for more details.                  *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Library General Public     *
00017  *   License along with this library; see the file COPYING.LIB. If not,    *
00018  *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
00019  *   Suite 330, Boston, MA  02111-1307, USA                                *
00020  *                                                                         *
00021  ***************************************************************************/
00022 
00023 
00024 #include "PreCompiled.h"
00025 #ifndef _PreComp_
00026 #endif
00027 
00028 
00029 #include "Placement.h"
00030 #include "Rotation.h"
00031 
00032 using namespace Base;
00033 
00034 Placement::Placement()
00035 {
00036 
00037 }
00038 
00039 Placement::Placement(const Base::Matrix4D& matrix)
00040 {
00041     fromMatrix(matrix);
00042 }
00043 
00044 Placement::Placement(const Placement& that)
00045 {
00046     this->_pos = that._pos;
00047     this->_rot = that._rot;
00048 }
00049 
00050 Placement::Placement(const Vector3d& Pos, const Rotation &Rot)
00051 {
00052     this->_pos = Pos;
00053     this->_rot = Rot;
00054 }
00055 
00056 Placement::Placement(const Vector3d& Pos, const Rotation &Rot, const Vector3d& Cnt)
00057 {
00058     Vector3d RotC = Cnt;
00059     Rot.multVec(RotC, RotC);
00060     this->_pos = Pos + Cnt - RotC;
00061     this->_rot = Rot;
00062 }
00063 
00064 Base::Matrix4D Placement::toMatrix(void) const
00065 {
00066     Base::Matrix4D matrix;
00067     _rot.getValue(matrix);
00068     matrix[0][3] = this->_pos.x;
00069     matrix[1][3] = this->_pos.y;
00070     matrix[2][3] = this->_pos.z;
00071     return matrix;
00072 }
00073 
00074 void Placement::fromMatrix(const Base::Matrix4D& matrix)
00075 {
00076     _rot.setValue(matrix);
00077     this->_pos.x = matrix[0][3];
00078     this->_pos.y = matrix[1][3];
00079     this->_pos.z = matrix[2][3];
00080 }
00081 
00082 void Placement::invert()
00083 {
00084     this->_rot = this->_rot.inverse();
00085     this->_rot.multVec(this->_pos, this->_pos);
00086     this->_pos = -this->_pos;
00087 }
00088 
00089 Placement Placement::inverse() const
00090 {
00091     Placement p(*this);
00092     p.invert();
00093     return p;
00094 }
00095 
00096 void Placement::move(const Vector3d& MovVec)
00097 {
00098     _pos += MovVec;
00099 }
00100 
00101 bool Placement::operator == (const Placement& that) const
00102 {
00103     return (this->_pos == that._pos) && (this->_rot == that._rot);
00104 }
00105 
00106 bool Placement::operator != (const Placement& that) const
00107 {
00108     return !(*this == that);
00109 }
00110 
00111 Placement & Placement::operator*=(const Placement & p)
00112 {
00113     Base::Vector3d tmp(p._pos);
00114     this->_rot.multVec(tmp, tmp);
00115     this->_pos += tmp;
00116     this->_rot *= p._rot;
00117     return *this;
00118 }
00119 
00120 Placement Placement::operator*(const Placement & p) const
00121 {
00122     Placement plm(*this);
00123     plm *= p;
00124     return plm;
00125 }
00126 
00127 Placement& Placement::operator = (const Placement& New)
00128 {
00129     this->_pos = New._pos;
00130     this->_rot = New._rot;
00131     return *this;
00132 }
00133 
00134 void Placement::multVec(const Vector3d & src, Vector3d & dst) const
00135 {
00136     this->_rot.multVec(src, dst);
00137     dst += this->_pos;
00138 }
00139 
00140 Placement Placement::slerp(const Placement & p0, const Placement & p1, double t)
00141 {
00142     Rotation rot = Rotation::slerp(p0.getRotation(), p1.getRotation(), t);
00143     Vector3d pos = p0.getPosition() * (1.0-t) + p1.getPosition() * t;
00144     return Placement(pos, rot);
00145 }

Generated on Wed Nov 23 19:00:26 2011 for FreeCAD by  doxygen 1.6.1