Quaternion

Quaternion — Simple quaternion handling

Functions

Types and Values

struct quaternion

Includes

#include "utils.h"

Description

There is a simple quaternion structure in CrystFEL. At the moment, it is only used when simulating patterns, as an argument to cell_rotate() to orient the unit cell.

Functions

quaternion_modulus ()

double
quaternion_modulus (struct quaternion q);

If a quaternion represents a pure rotation, its modulus should be unity.

Parameters

q

A quaternion

 

Returns

the modulus of the given quaternion.


normalise_quaternion ()

struct quaternion
normalise_quaternion (struct quaternion q);

Rescales the quaternion such that its modulus is unity.

Parameters

q

A quaternion

 

Returns

the normalised version of q


random_quaternion ()

struct quaternion
random_quaternion (gsl_rng *rng);

Parameters

rng

A GSL random number generator to use

 

Returns

a randomly generated, normalised, quaternion.


quaternion_valid ()

int
quaternion_valid (struct quaternion q);

Checks if the given quaternion is normalised.

This function performs a nasty floating point comparison of the form

(modulus > 0.999) && (modulus < 1.001), and so should not be

relied upon to spot anything other than the most obvious input error.

Parameters

q

A quaternion

 

Returns

1 if the quaternion is normalised, 0 if not.


quat_rot ()

struct rvec
quat_rot (struct rvec q,
          struct quaternion z);

Rotates a vector according to a quaternion.

Parameters

q

A vector (in the form of a "struct rvec")

 

z

A quaternion

 

Returns

A rotated version of p .

Types and Values

struct quaternion

struct quaternion {
	double w;
	double x;
	double y;
	double z;
};
struct quaternion
{
   double w
   double x
   double y
   double z
};

A structure representing a quaternion.