Public Member Functions | Public Attributes

MeshLib::CQrot Class Reference

CQrot quaternion class. More...

#include <Quat.h>

Collaboration diagram for MeshLib::CQrot:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 CQrot ()
 CQrot (double w, double x, double y, double z)
 CQrot (const CQrot &q)
CQrotoperator= (const CQrot &q)
 ~CQrot ()
CQrotoperator^ (double p)
void convert (double *m)
CPoint operator* (const CPoint &p)
void normalize ()
CQrot operator* (const CQrot &q) const
double operator^ (const CQrot &q) const

Public Attributes

double m_w
double m_x
double m_y
double m_z

Detailed Description

CQrot quaternion class.

Definition at line 23 of file Quat.h.


Constructor & Destructor Documentation

MeshLib::CQrot::CQrot (  )  [inline]

CQrot default constructor

Definition at line 29 of file Quat.h.

{m_w=1; m_x=m_y=m_z=0;};

Here is the caller graph for this function:

MeshLib::CQrot::CQrot ( double  w,
double  x,
double  y,
double  z 
) [inline]

CQrot default constructor

Parameters:
w w-value
x x-value
y y-value
z z-value

Definition at line 39 of file Quat.h.

  {
    m_w = w;
    m_x = x;
    m_y = y;
    m_z = z;
  };

MeshLib::CQrot::CQrot ( const CQrot q  )  [inline]

Copy operator of CQrot

Parameters:
q a quaternion

Definition at line 50 of file Quat.h.

  {
    m_w = q.m_w; 
    m_x =  q.m_x; 
    m_y =  q.m_y; 
    m_z =  q.m_z;
  }

MeshLib::CQrot::~CQrot (  )  [inline]

CQrot destructor

Definition at line 72 of file Quat.h.

{};


Member Function Documentation

void CQrot::convert ( double *  m  ) 

Convert quoternion to OpenGL matrix

Parameters:
m pointer to the matrix

convert the current quoternion to OpenGL matrix

Parameters:
m pointer to the matrix

Definition at line 97 of file Quat.cpp.

{
  CQrot q = *this;
  double l = q^q;
  double s = 2.0 / l;
  double xs = q.m_x*s;
  double ys = q.m_y*s;
  double zs = q.m_z*s;
  
  double wx = q.m_w*xs;
  double wy = q.m_w*ys;
  double wz = q.m_w*zs;
  
  double xx = q.m_x*xs;
  double xy = q.m_x*ys;
  double xz = q.m_x*zs;
  
  double yy = q.m_y*ys;
  double yz = q.m_y*zs;
  double zz = q.m_z*zs;
  

  m[0*4+0] = 1.0 - (yy + zz);
  m[1*4+0] = xy - wz;
  m[2*4+0] = xz + wy;
  m[0*4+1] = xy + wz;
  m[1*4+1] = 1.0 - (xx + zz);
  m[2*4+1] = yz - wx;
  m[0*4+2] = xz - wy;
  m[1*4+2] = yz + wx;
  m[2*4+2] = 1.0 - (xx + yy);

  
  m[0*4+3] = 0.0;
  m[1*4+3] = 0.0;
  m[2*4+3] = 0.0;
  m[3*4+0] = m[3*4+1] = m[3*4+2] = 0.0;
  m[3*4+3] = 1.0;
}

void CQrot::normalize (  ) 

normalization

Definition at line 15 of file Quat.cpp.

{
  double l = m_w * m_w + m_x * m_x + m_y * m_y + m_z * m_z;
    if( l < 1e-20 ) {  
        m_x = 0; m_y = 0; m_z = 0; m_w = 1;
        return;
    }

    l = sqrt(l);

    m_w /= l;
    m_x /= l;
    m_y /= l;
    m_z /= l;
}

Here is the caller graph for this function:

CPoint CQrot::operator* ( const CPoint p  ) 

Multiply a point with the current quoternion

Parameters:
p input point
Returns:
product of the current quoternion with v

Product of a quoternion with a point

Parameters:
p input point
Returns:
the product of the quoternion and the point

Definition at line 58 of file Quat.cpp.

{
    CQrot   q(m_w,m_x,m_y,m_z);
    CQrot pq( 0, p[0],p[1], p[2]);
    CQrot iq = q^(-1);
    CQrot r =     q *  pq * iq ;
    return CPoint(r.m_x,r.m_y, r.m_z);
}

CQrot CQrot::operator* ( const CQrot q  )  const

product of two quoternions

Parameters:
q input quoternion
Returns:
product of the current quoternion and q

Definition at line 144 of file Quat.cpp.

{

    double   sp = m_w;
    CPoint vp( m_x, m_y, m_z );

    double   sq = q.m_w;
    CPoint vq( q.m_x, q.m_y, q.m_z );
 
    double   sr = sp * sq - vp * vq;

    CPoint vr;
    CPoint dp;
    dp = vp^vq;
    vp = vp * sq;
    vq = vq * sp;
    vr = vp   + vq + dp;

    return CQrot( sr, vr[0], vr[1], vr[2]);
}

Here is the call graph for this function:

CQrot& MeshLib::CQrot::operator= ( const CQrot q  )  [inline]

Copy operator of CQrot

Parameters:
q a quaternion

Definition at line 61 of file Quat.h.

  {
      m_w = q.m_w;
      m_x  = q.m_x;
      m_y  = q.m_y;
      m_z  = q.m_z;
      return *this;
  }

double CQrot::operator^ ( const CQrot q  )  const

inner product of two quoternions

Parameters:
q input quoternion
Returns:
inner product of the current quoternion and q

Definition at line 171 of file Quat.cpp.

{
  return ( m_w * q.m_w + m_x * q.m_x + m_y * q.m_y + m_z * q.m_z);
};

CQrot & CQrot::operator^ ( double  p  ) 

power of quaternion

Parameters:
p power
Returns:
quoternion power p

Definition at line 35 of file Quat.cpp.

{
  normalize();
  double theta = 2 * acos( m_w );
  if( theta < 1e-10 ) return (*this); 

  CPoint axis( m_x,m_y,m_z );
  axis /= axis.norm();

  theta *= p;
  m_w   = cos( theta * 0.5 );
  axis *= sin( theta * 0.5 );

  m_x = axis[0];
  m_y = axis[1];
  m_z = axis[2];

  return (*this);
}

Here is the call graph for this function:


Member Data Documentation

(x,y,z,w) value of the current quoternion

Definition at line 96 of file Quat.h.

Definition at line 96 of file Quat.h.

Definition at line 96 of file Quat.h.

Definition at line 96 of file Quat.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Defines