Subversion Repositories gelsvn

Rev

Rev 49 | Rev 89 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 49 Rev 51
Line 107... Line 107...
107
			   0.0),
107
			   0.0),
108
		     Vec4d(0.0, 0.0, 0.0, 1.0));
108
		     Vec4d(0.0, 0.0, 0.0, 1.0));
109
    }
109
    }
110
 
110
 
111
    /// Obtain angle of rotation and axis
111
    /// Obtain angle of rotation and axis
112
    void get_rot(double& angle, Vec3d& vec)
112
    void get_rot(double& angle, Vec3d& v)
113
    {
113
    {
114
      angle = 2*std::acos(qw);
114
      angle = 2*std::acos(qw);
115
 
115
 
116
      if(angle < TINY) 
116
      if(angle < TINY) 
117
	v = Vec3d(1.0, 0.0, 0.0);
117
	v = Vec3d(1.0, 0.0, 0.0);
Line 123... Line 123...
123
 
123
 
124
      v.normalize();
124
      v.normalize();
125
    }
125
    }
126
 
126
 
127
    /// Construct a Quaternion from an angle and axis of rotation.
127
    /// Construct a Quaternion from an angle and axis of rotation.
128
    void make_rot(double angle, const Vec3d&)
128
    void make_rot(double angle, const Vec3d& v)
129
    {
129
    {
130
      angle /= 2.0;
130
      angle /= 2.0;
131
      qv = CGLA::normalize(v)*std::sin(angle);
131
      qv = CGLA::normalize(v)*std::sin(angle);
132
      qw = std::cos(angle);
132
      qw = std::cos(angle);
133
    }
133
    }
134
 
134
 
135
    /** Construct a Quaternion rotating from the direction given
135
    /** Construct a Quaternion rotating from the direction given
136
	by the first argument to the direction given by the second.*/
136
	by the first argument to the direction given by the second.*/
137
    void make_rot(const Vec3d&,const Vec3d&)
137
    void make_rot(const Vec3d& s,const Vec3d& t)
138
    {
138
    {
139
      double tmp = std::sqrt(2*(1 + dot(s, t)));
139
      double tmp = std::sqrt(2*(1 + dot(s, t)));
140
      qv = cross(s, t)*(1.0/tmp);
140
      qv = cross(s, t)*(1.0/tmp);
141
      qw = tmp/2.0;    
141
      qw = tmp/2.0;    
142
    }
142
    }