include/vamos/body/Frame.h

Go to the documentation of this file.
00001 // Frame.h - a coordinate system.
00002 //
00003 //  Copyright (C) 2001--2004 Sam Varner
00004 //
00005 //  This file is part of Vamos Automotive Simulator.
00006 //
00007 //  This program is free software; you can redistribute it and/or modify
00008 //  it under the terms of the GNU General Public License as published by
00009 //  the Free Software Foundation; either version 2 of the License, or
00010 //  (at your option) any later version.
00011 //
00012 //  This program is distributed in the hope that it will be useful,
00013 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 //  GNU General Public License for more details.
00016 //
00017 //  You should have received a copy of the GNU General Public License
00018 //  along with this program; if not, write to the Free Software
00019 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 
00021 #ifndef _FRAME_H_
00022 #define _FRAME_H_
00023 
00024 #include <vamos/geometry/Three_Vector.h>
00025 #include <vamos/geometry/Three_Matrix.h>
00026 
00027 namespace Vamos_Body
00028 {
00029   //* A Frame describes a coordinate system.
00030   class Frame
00031   {
00032   protected:
00033     // The position of the origin of this frame relative to the parent frame.
00034     Vamos_Geometry::Three_Vector m_position;
00035 
00036     // The orientation of this frame relative to the parent frame.  The columns
00037     // of the matrix are the unit vectors of the x, y, and z axes.  This is
00038     // also the transformation matrix for rotating vectors into and out of
00039     // this frame.  See rotate_in () and rotate_out ().
00040     Vamos_Geometry::Three_Matrix m_orientation;
00041 
00042     // The position of the origin of this frame relative to the parent
00043     // frame.  This is the vector from the parent frame's origin to
00044     // this frame's origin, expressed in the coordinates of the parent
00045     // frame.
00046     Vamos_Geometry::Three_Vector m_velocity;
00047 
00048     // The angular velocity vector of this frame expressed in the
00049     // coordinates of the parent's frame.
00050     Vamos_Geometry::Three_Vector m_ang_velocity;
00051 
00052   public:
00053     //** Constructors
00054 
00055     // Specify the position and orientation.
00056     Frame (const Vamos_Geometry::Three_Vector& position, 
00057            const Vamos_Geometry::Three_Matrix& orientation);
00058 
00059     // Take the parent's orientation.
00060     Frame (const Vamos_Geometry::Three_Vector& position);
00061 
00062     // Make a frame that's coincident with the parent frame.
00063     Frame ();
00064 
00065     // VEC is a vector in the parent's frame.  The representation of
00066     // VEC in this frame is returned.
00067     Vamos_Geometry::Three_Vector 
00068     transform_in (const Vamos_Geometry::Three_Vector& vec) const;
00069 
00070     // VEC is a vector in this frame.  The representation of VEC in
00071     // the parent's frame is returned.
00072     Vamos_Geometry::Three_Vector 
00073     transform_out (const Vamos_Geometry::Three_Vector& vec) const;
00074 
00075     // Same as transform_out (VEC) above, except that the rotation is
00076     // about the point PIVOT expressed in this frame's coordinates.
00077     Vamos_Geometry::Three_Vector 
00078     transform_out (const Vamos_Geometry::Three_Vector& vec,
00079                    const Vamos_Geometry::Three_Vector& pivot) const;
00080 
00081     // Same as transform_in (VEC) above, except that translation is
00082     // not performed.
00083     Vamos_Geometry::Three_Vector 
00084     rotate_in (const Vamos_Geometry::Three_Vector& vec) const
00085     { return m_orientation.transpose () * vec; }
00086 
00087     // Same as transform_out (VEC) above, except that translation is
00088     // not performed.
00089     Vamos_Geometry::Three_Vector 
00090     rotate_out (const Vamos_Geometry::Three_Vector& vec) const
00091     { return m_orientation * vec; }
00092 
00093     // Change the position by DELTA_R.
00094     void translate (const Vamos_Geometry::Three_Vector& delta_r) 
00095     { m_position += delta_r; }
00096 
00097     // Rotate the frame about the vector delta_theta, by an angle equal to
00098     // the magnitude of DELTA_THETA.
00099     void rotate (const Vamos_Geometry::Three_Vector& delta_theta);
00100 
00101     // Put this frame's origin at NEW_POSITION in the parent's
00102     // coordinates.
00103     void place (const Vamos_Geometry::Three_Vector& new_position) 
00104     { m_position = new_position; }
00105 
00106     // Give this frame an absolute orientation of NEW_ORIENTATION.
00107     void orient (const Vamos_Geometry::Three_Matrix& new_orientation)
00108     { m_orientation = new_orientation; }
00109 
00110     // Express the orientation of this frame as a vector in the parent
00111     // frame and a rotation about that vector.  ANGLE holds the
00112     // rotation angle when the function returns.  The returned vector
00113     // has a magnitude of sin (ANGLE).  The values returned are
00114     // suitable for use with the glRotate functions.
00115     Vamos_Geometry::Three_Vector axis_angle (double* angle) const;
00116 
00117     // Return the position of the origin in the parent frame.
00118     Vamos_Geometry::Three_Vector position () const { return m_position; };
00119 
00120     // Return the orientation matrix of the frame relative to the
00121     // parent frame.
00122     Vamos_Geometry::Three_Matrix orientation () const { return m_orientation; }
00123 
00124     // Return the velocity of the origin relative to the parent frame.
00125     Vamos_Geometry::Three_Vector velocity () const { return m_velocity; }
00126 
00127     // Return the angular velocity of the frame relative to the parent
00128     // frame.
00129     Vamos_Geometry::Three_Vector ang_velocity () const 
00130     { return m_ang_velocity; }
00131         
00132         void set_ang_velocity(Vamos_Geometry::Three_Vector newangvel) {m_ang_velocity = newangvel;}
00133         void set_velocity(Vamos_Geometry::Three_Vector newvel) {m_velocity = newvel;}
00134   };
00135 }
00136 
00137 #endif // not _FRAME_H_

Generated on Thu Oct 19 04:05:47 2006 by  doxygen 1.4.6