NcmQuaternion

NcmQuaternion — Quaternions algebra, three-vectors and mapping to matrix.

Functions

Types and Values

Object Hierarchy

    GBoxed
    ├── NcmQuaternion
    ╰── NcmTriVec

Description

A quaternion is a four-dimensional vector that can be used to represent rotations in three-dimensional space. The three-dimensional space is represented by the three-dimensional subspace of the quaternions that have zero real part.

This object also implements three-dimensional vectors and the mapping of quaternions to rotation matrices.

Functions

ncm_trivec_new ()

NcmTriVec *
ncm_trivec_new (void);

Creates a new empty NcmTriVec.

[constructor]

Returns

a new NcmTriVec.

[transfer full]


ncm_trivec_new_full ()

NcmTriVec *
ncm_trivec_new_full (const gdouble c[3]);

Creates a new NcmTriVec with the given components.

[constructor]

Parameters

c

components

 

Returns

the new NcmTriVec.

[transfer full]


ncm_trivec_new_full_c ()

NcmTriVec *
ncm_trivec_new_full_c (const gdouble x,
                       const gdouble y,
                       const gdouble z);

Creates a new NcmTriVec with the given components.

[constructor]

Parameters

x

x-component

 

y

y-component

 

z

z-component

 

Returns

the new NcmTriVec.

[transfer full]


ncm_trivec_dup ()

NcmTriVec *
ncm_trivec_dup (NcmTriVec *v);

Duplicates a NcmTriVec.

Parameters

v

a NcmTriVec

 

Returns

a new NcmTriVec.

[transfer full]


ncm_trivec_free ()

void
ncm_trivec_free (NcmTriVec *v);

Frees a NcmTriVec.

Parameters

v

a NcmTriVec

 

ncm_trivec_memcpy ()

void
ncm_trivec_memcpy (NcmTriVec *dest,
                   const NcmTriVec *orig);

Copies a NcmTriVec.

Parameters

dest

a NcmTriVec

 

orig

a NcmTriVec

 

ncm_trivec_set_0 ()

void
ncm_trivec_set_0 (NcmTriVec *v);

Sets a NcmTriVec to zero.

Parameters

v

a NcmTriVec

 

ncm_trivec_scale ()

void
ncm_trivec_scale (NcmTriVec *v,
                  const gdouble scale);

Scale a NcmTriVec.

Parameters

v

a NcmTriVec

 

scale

FIXME

 

ncm_trivec_norm ()

gdouble
ncm_trivec_norm (NcmTriVec *v);

Calculates the norm of a NcmTriVec.

Parameters

v

a NcmTriVec

 

Returns

the norm of v .


ncm_trivec_dot ()

gdouble
ncm_trivec_dot (const NcmTriVec *v1,
                const NcmTriVec *v2);

Calculates the dot product of two NcmTriVec.

Parameters

v1

a NcmTriVec

 

v2

a NcmTriVec

 

Returns

the dot product of v1 and v2 .


ncm_trivec_normalize ()

void
ncm_trivec_normalize (NcmTriVec *v);

Normalize a NcmTriVec.

Parameters

v

a NcmTriVec

 

ncm_trivec_get_phi ()

gdouble
ncm_trivec_get_phi (NcmTriVec *v);

Gets the azimuthal angle of a NcmTriVec.

Parameters

v

a NcmTriVec

 

Returns

the azimuthal angle of v .


ncm_trivec_set_spherical_coord ()

void
ncm_trivec_set_spherical_coord (NcmTriVec *v,
                                gdouble r,
                                gdouble theta,
                                gdouble phi);

Sets the spherical coordinates of a NcmTriVec.

Parameters

v

a NcmTriVec

 

r

the radius

 

theta

the polar angle

 

phi

the azimuthal angle

 

ncm_trivec_get_spherical_coord ()

void
ncm_trivec_get_spherical_coord (NcmTriVec *v,
                                gdouble *theta,
                                gdouble *phi);

Computes the spherical coordinates of a NcmTriVec.

Parameters

v

a NcmTriVec

 

theta

the polar angle.

[out]

phi

the azimuthal angle.

[out]

ncm_quaternion_new ()

NcmQuaternion *
ncm_quaternion_new (void);

Creates a new empty NcmQuaternion.

[constructor]

Returns

a new NcmQuaternion.

[transfer full]


ncm_quaternion_new_from_vector ()

NcmQuaternion *
ncm_quaternion_new_from_vector (NcmTriVec *v);

Creates a new NcmQuaternion from a NcmTriVec.

[constructor]

Parameters

v

a NcmTriVec

 

Returns

a new NcmQuaternion.

[transfer full]


ncm_quaternion_new_from_data ()

NcmQuaternion *
ncm_quaternion_new_from_data (gdouble x,
                              gdouble y,
                              gdouble z,
                              gdouble theta);

Creates a new NcmQuaternion from the given components. See ncm_quaternion_set_from_data() for details.

[constructor]

Parameters

x

the x-component

 

y

the y-component

 

z

the z-component

 

theta

the angle

 

Returns

a new NcmQuaternion.

[transfer full]


ncm_quaternion_dup ()

NcmQuaternion *
ncm_quaternion_dup (NcmQuaternion *q);

Duplicates a NcmQuaternion.

Parameters

q

a NcmQuaternion

 

Returns

a new NcmQuaternion.

[transfer full]


ncm_quaternion_free ()

void
ncm_quaternion_free (NcmQuaternion *q);

Frees a NcmQuaternion.

Parameters

q

a NcmQuaternion

 

ncm_quaternion_memcpy ()

void
ncm_quaternion_memcpy (NcmQuaternion *dest,
                       const NcmQuaternion *orig);

Copies a NcmQuaternion.

Parameters

dest

a NcmQuaternion

 

orig

a NcmQuaternion

 

ncm_quaternion_set_from_data ()

void
ncm_quaternion_set_from_data (NcmQuaternion *q,
                              gdouble x,
                              gdouble y,
                              gdouble z,
                              gdouble theta);

Sets the components of a NcmQuaternion. The components are the components of a three-dimensional vector and the angle of rotation, the three-dimensional vector is normalized. The final form of the quaternion is: $$q = \cos(\theta/2) + \sin(\theta/2) \hat{v}.$$

Parameters

q

a NcmQuaternion

 

x

the x-component

 

y

the y-component

 

z

the z-component

 

theta

the angle

 

ncm_quaternion_set_random ()

void
ncm_quaternion_set_random (NcmQuaternion *q,
                           NcmRNG *rng);

Sets a NcmQuaternion to a random value, using the given NcmRNG. The components of the three-dimensional vector are uniformly distributed in the interval [-1, 1] and the angle is uniformly distributed in the interval [0, 2*pi].

It represents a random rotation in three-dimensional space.

Parameters

q

a NcmQuaternion

 

rng

a NcmRNG

 

ncm_quaternion_set_I ()

void
ncm_quaternion_set_I (NcmQuaternion *q);

Sets a NcmQuaternion to the identity.

Parameters

q

a NcmQuaternion

 

ncm_quaternion_set_0 ()

void
ncm_quaternion_set_0 (NcmQuaternion *q);

Sets a NcmQuaternion to zero.

Parameters

q

a NcmQuaternion

 

ncm_quaternion_norm ()

gdouble
ncm_quaternion_norm (NcmQuaternion *q);

Calculates the norm of a NcmQuaternion.

Parameters

q

a NcmQuaternion

 

Returns

the norm of q .


ncm_quaternion_normalize ()

void
ncm_quaternion_normalize (NcmQuaternion *q);

Normalize a NcmQuaternion.

Parameters

q

a NcmQuaternion

 

ncm_quaternion_conjugate ()

void
ncm_quaternion_conjugate (NcmQuaternion *q);

Conjugate a NcmQuaternion. That is, the vector part is negated.

Parameters

q

a NcmQuaternion

 

ncm_quaternion_mul ()

void
ncm_quaternion_mul (NcmQuaternion *q,
                    NcmQuaternion *u,
                    NcmQuaternion *res);

Computes the product of two NcmQuaternion and stores the result in res .

Parameters

q

a NcmQuaternion

 

u

a NcmQuaternion

 

res

a NcmQuaternion

 

ncm_quaternion_lmul ()

void
ncm_quaternion_lmul (NcmQuaternion *q,
                     NcmQuaternion *u);

Computes the product of two NcmQuaternion and stores the result in q . That is, q = u * q .

Parameters


ncm_quaternion_rmul ()

void
ncm_quaternion_rmul (NcmQuaternion *q,
                     NcmQuaternion *u);

Computes the product of two NcmQuaternion and stores the result in q . That is, q = q * u .

Parameters


ncm_quaternion_conjugate_u_mul ()

void
ncm_quaternion_conjugate_u_mul (NcmQuaternion *q,
                                NcmQuaternion *u,
                                NcmQuaternion *res);

Computes the product of two NcmQuaternion and stores the result in res . The second NcmQuaternion is conjugated before the multiplication.

Parameters

q

a NcmQuaternion

 

u

a NcmQuaternion

 

res

a NcmQuaternion

 

ncm_quaternion_conjugate_q_mul ()

void
ncm_quaternion_conjugate_q_mul (NcmQuaternion *q,
                                NcmQuaternion *u,
                                NcmQuaternion *res);

Computes the product of two NcmQuaternion and stores the result in res . The first NcmQuaternion is conjugated before the multiplication.

Parameters

q

a NcmQuaternion

 

u

a NcmQuaternion

 

res

a NcmQuaternion

 

ncm_quaternion_rotate ()

void
ncm_quaternion_rotate (NcmQuaternion *q,
                       NcmTriVec *v);

Computes the rotation of a NcmTriVec by a NcmQuaternion.

Parameters

q

a NcmQuaternion

 

v

a NcmTriVec

 

ncm_quaternion_inv_rotate ()

void
ncm_quaternion_inv_rotate (NcmQuaternion *q,
                           NcmTriVec *v);

Computes the inverse rotation of a NcmTriVec by a NcmQuaternion.

Parameters

q

a NcmQuaternion

 

v

a NcmTriVec

 

Types and Values

NCM_QUATERNION_INIT

#define NCM_QUATERNION_INIT {0.0, {{0.0, 0.0, 0.0}}}

NCM_QUATERNION_INIT_I

#define NCM_QUATERNION_INIT_I {1.0, {{0.0, 0.0, 0.0}}}