40 #ifndef GEOGRAM_BASIC_QUATERNION
41 #define GEOGRAM_BASIC_QUATERNION
85 double x,
double y,
double z,
double w
86 ) : v_(x,y,z), s_(w) {
124 void print( std::ostream& out )
const {
125 out << v_.x <<
" " << v_.y <<
" " << v_.z <<
" " << s_ ;
142 v_ = ax * ::sin(f / 2.0);
149 set_angle( f *
angle() );
157 return 2.0 * acos( s_ ) ;
213 inline std::ostream& operator<<(std::ostream& out,
const Quaternion& q) {
225 inline std::istream& operator>>(std::istream& in,
Quaternion& q) {
226 double x=0.0,y=0.0,z=0.0,w=0.0 ;
227 in >> x >> y >> z >> w ;
276 a.
s() * b.
v() + b.
s() * a.
v() + cross(a.
v(),b.
v()),
277 a.
s() * b.
s() - dot(a.
v() , b.
v())
Quaternions are useful for representing rotations.
static Quaternion spherical_interpolation(const Quaternion &from, const Quaternion &to, double t)
Computes the interpolation between two quaternions.
Quaternion(double x, double y, double z, double w)
Constructs a new quaternion from its coefficients.
double angle() const
Gets the rotation angle.
void set(const vec3 &v, double s)
Sets the coefficients of this quaterion.
vec3 axis() const
Gets the axis.
Quaternion()
Constructs a new Quaternion.
const vec3 & v() const
Gets the vector component.
double s() const
Gets the scalar component.
void print(std::ostream &out) const
Displays this Quaternion.
void set_angle(double f)
Sets the rotation angle.
Quaternion(const Quaternion &rhs)
Copy-constructs a new Quaternion.
void scale_angle(double f)
Scales the rotation angle.
Quaternion(const vec3 &v, double s)
Constructs a new Quaternion from a vector and a scalar.
mat4 to_matrix() const
Converts this Quaternion into a matrix.
Common include file, providing basic definitions. Should be included before anything else by all head...
Geometric functions in 2d and 3d.
double angle(const vec3 &a, const vec3 &b)
Computes the angle between two 3d vectors.
Global Vorpaline namespace.
Quaternion operator-(const Quaternion &a, const Quaternion &b)
Computes the difference between two Quaternion.
vecng< 3, Numeric::float64 > vec3
Represents points and vectors in 3d.
Quaternion operator+(const Quaternion &a, const Quaternion &b)
Computes the sum of two Quaternion.