Data Structures | Typedefs | Functions
EPhysics Quaternion

Quaternions are used to perform linear algebra rotations. More...

Data Structures

struct  _EPhysics_Quaternion
 Quaternion coordinates and rotation (w, x, y, z) More...
 

Typedefs

typedef struct _EPhysics_Quaternion EPhysics_Quaternion
 Quaternion handle, represents a quaternion to be used to rotate bodies. More...
 

Functions

EAPI EPhysics_Quaternionephysics_quaternion_new (void)
 Create a new quaternion. More...
 
EAPI void ephysics_quaternion_get (const EPhysics_Quaternion *quat, double *x, double *y, double *z, double *w)
 Get quaternion values. More...
 
EAPI void ephysics_quaternion_axis_angle_get (const EPhysics_Quaternion *quat, double *nx, double *ny, double *nz, double *a)
 Get quaternion axis and angle. More...
 
EAPI void ephysics_quaternion_set (EPhysics_Quaternion *quat, double x, double y, double z, double w)
 Set quaternion values. More...
 
EAPI void ephysics_quaternion_axis_angle_set (EPhysics_Quaternion *quat, double nx, double ny, double nz, double a)
 Set quaternion using axis angle notation. More...
 
EAPI void ephysics_quaternion_euler_set (EPhysics_Quaternion *quat, double yaw, double pitch, double roll)
 Set quaternion using Euler angles. More...
 
EAPI void ephysics_quaternion_normalize (EPhysics_Quaternion *quat)
 Normalize the quaternion. More...
 
EAPI void ephysics_quaternion_invert (EPhysics_Quaternion *quat)
 Invert the quaternion. More...
 
EAPI void ephysics_quaternion_scale (EPhysics_Quaternion *quat, double scale)
 Scale the quaternion. More...
 
EAPI void ephysics_quaternion_inverse_scale (EPhysics_Quaternion *quat, double scale)
 Inversely scale the quaternion. More...
 
EAPI EPhysics_Quaternionephysics_quaternion_sum (const EPhysics_Quaternion *quat1, const EPhysics_Quaternion *quat2, EPhysics_Quaternion *result)
 Returns a sum of two quaternions. More...
 
EAPI EPhysics_Quaternionephysics_quaternion_diff (const EPhysics_Quaternion *quat1, const EPhysics_Quaternion *quat2, EPhysics_Quaternion *result)
 Returns a difference between two quaternions. More...
 
EAPI EPhysics_Quaternionephysics_quaternion_multiply (const EPhysics_Quaternion *quat1, const EPhysics_Quaternion *quat2, EPhysics_Quaternion *result)
 Multiply two quaternions. More...
 
EAPI EPhysics_Quaternionephysics_quaternion_slerp (const EPhysics_Quaternion *quat1, const EPhysics_Quaternion *quat2, double ratio, EPhysics_Quaternion *result)
 Return the quaternion which is the result of Spherical Linear Interpolation between two quaternions. More...
 
EAPI double ephysics_quaternion_dot (const EPhysics_Quaternion *quat1, const EPhysics_Quaternion *quat2)
 Return the dot product between two quaternions. More...
 
EAPI double ephysics_quaternion_angle_get (const EPhysics_Quaternion *quat1, const EPhysics_Quaternion *quat2)
 Return the angle between two quaternions. More...
 
EAPI double ephysics_quaternion_length_get (const EPhysics_Quaternion *quat)
 Return the length of the quaternion. More...
 
EAPI double ephysics_quaternion_length2_get (const EPhysics_Quaternion *quat)
 Return the length squared of the quaternion. More...
 

Detailed Description

Quaternions are used to perform linear algebra rotations.

Functions regarding rotation, like ephysics_body_rotation_set() and ephysics_body_rotation_get() would need that. Quaternions can be used to rotate evas maps as well, with evas_map_util_quat_rotate(), but in this case quaternion values need to be get with ephysics_quaternion_get(), since evas don't accept EPhysics_Quaternion type.

A quaternion can be created with ephysics_quaternion_new(), and many operations can be performed with that, as:

Typedef Documentation

◆ EPhysics_Quaternion

Quaternion handle, represents a quaternion to be used to rotate bodies.

Created with ephysics_quaternion_new() and deleted with free().

Function Documentation

◆ ephysics_quaternion_new()

EAPI EPhysics_Quaternion* ephysics_quaternion_new ( void  )

Create a new quaternion.

By default a quaternion is created as identity (w = 1, x = 0, y = 0, z = 0). This values can be modified later by quaternion operations or set directly.

Returns
The created quaternion or NULL on error.
Note
It should be deleted with free() after usage is concluded.
See also
ephysics_quaternion_set();
ephysics_quaternion_axis_angle_set();
ephysics_quaternion_euler_set();
ephysics_quaternion_scale();
ephysics_quaternion_sum();

◆ ephysics_quaternion_get()

EAPI void ephysics_quaternion_get ( const EPhysics_Quaternion quat,
double *  x,
double *  y,
double *  z,
double *  w 
)

Get quaternion values.

Parameters
quatQuaternion to get values from.
xThe x coordinate.
yThe y coordinate.
zThe z coordinate.
wThe rotation.
See also
ephysics_quaternion_set();
Examples
test_rotating_forever.c.

◆ ephysics_quaternion_axis_angle_get()

EAPI void ephysics_quaternion_axis_angle_get ( const EPhysics_Quaternion quat,
double *  nx,
double *  ny,
double *  nz,
double *  a 
)

Get quaternion axis and angle.

Parameters
quatQuaternion to get values from.
nxThe x component of the axis of rotation.
nyThe y component of the axis of rotation.
nzThe z component of the axis of rotation.
aThe angle of rotation.
See also
ephysics_quaternion_axis_angle_set();
ephysics_quaternion_get();
ephysics_quaternion_set();

◆ ephysics_quaternion_set()

EAPI void ephysics_quaternion_set ( EPhysics_Quaternion quat,
double  x,
double  y,
double  z,
double  w 
)

Set quaternion values.

Parameters
quatQuaternion to be set.
xThe x coordinate.
yThe y coordinate.
zThe z coordinate.
wThe rotation.
See also
ephysics_quaternion_get();
ephysics_quaternion_euler_set();
Examples
test_rotating_forever.c.

◆ ephysics_quaternion_axis_angle_set()

EAPI void ephysics_quaternion_axis_angle_set ( EPhysics_Quaternion quat,
double  nx,
double  ny,
double  nz,
double  a 
)

Set quaternion using axis angle notation.

[w, x, y, z] = [cos(a/2), sin(a/2) * nx, sin(a/2)* ny, sin(a/2) * nz]

Parameters
quatQuaternion to be set.
nxThe x component of the axis of rotation.
nyThe y component of the axis of rotation.
nzThe z component of the axis of rotation.
aThe angle of rotation.
See also
ephysics_quaternion_axis_angle_get();
ephysics_quaternion_set();
ephysics_quaternion_euler_set();

◆ ephysics_quaternion_euler_set()

EAPI void ephysics_quaternion_euler_set ( EPhysics_Quaternion quat,
double  yaw,
double  pitch,
double  roll 
)

Set quaternion using Euler angles.

It's an alternative to ephysics_quaternion_set() usage. Euler angles will be converted.

Parameters
quatQuaternion to be set.
yawThe angle around Y axis.
pitchThe angle around X axis.
rollThe angle around Z axis.
See also
ephysics_quaternion_get();
ephysics_quaternion_set();

◆ ephysics_quaternion_normalize()

EAPI void ephysics_quaternion_normalize ( EPhysics_Quaternion quat)

Normalize the quaternion.

A normalized quaternion is such that x^2 + y^2 + z^2 + w^2 = 1.

Parameters
quatQuaternion to be normalized.
Examples
test_rotating_forever.c.

◆ ephysics_quaternion_invert()

EAPI void ephysics_quaternion_invert ( EPhysics_Quaternion quat)

Invert the quaternion.

Parameters
quatQuaternion to be inverted.

◆ ephysics_quaternion_scale()

EAPI void ephysics_quaternion_scale ( EPhysics_Quaternion quat,
double  scale 
)

Scale the quaternion.

Parameters
quatQuaternion to be scaled.
scaleThe scale factor.
See also
ephysics_quaternion_inverse_scale()

◆ ephysics_quaternion_inverse_scale()

EAPI void ephysics_quaternion_inverse_scale ( EPhysics_Quaternion quat,
double  scale 
)

Inversely scale the quaternion.

Parameters
quatQuaternion to be scaled.
scaleThe scale factor.
See also
ephysics_quaternion_scale()

◆ ephysics_quaternion_sum()

EAPI EPhysics_Quaternion* ephysics_quaternion_sum ( const EPhysics_Quaternion quat1,
const EPhysics_Quaternion quat2,
EPhysics_Quaternion result 
)

Returns a sum of two quaternions.

Parameters
quat1First quaternion to sum.
quat2Second quaternion to sum.
resultQuaternion used to store the result. If it's NULL, a new quaternion will be allocated (and should be freed after usage).
Returns
The sum quaternion or NULL on error.

◆ ephysics_quaternion_diff()

EAPI EPhysics_Quaternion* ephysics_quaternion_diff ( const EPhysics_Quaternion quat1,
const EPhysics_Quaternion quat2,
EPhysics_Quaternion result 
)

Returns a difference between two quaternions.

Parameters
quat1First quaternion.
quat2Second quaternion.
resultQuaternion used to store the result. If it's NULL, a new quaternion will be allocated (and should be freed after usage).
Returns
The difference between quat1 and quat2, or NULL on error.

◆ ephysics_quaternion_multiply()

EAPI EPhysics_Quaternion* ephysics_quaternion_multiply ( const EPhysics_Quaternion quat1,
const EPhysics_Quaternion quat2,
EPhysics_Quaternion result 
)

Multiply two quaternions.

Parameters
quat1First quaternion.
quat2Second quaternion.
resultQuaternion used to store the result. If it's NULL, a new quaternion will be allocated (and should be freed after usage).
Returns
The quat1 multiplied by quat2 on the right, or NULL on error.
Examples
test_rotating_forever.c.

◆ ephysics_quaternion_slerp()

EAPI EPhysics_Quaternion* ephysics_quaternion_slerp ( const EPhysics_Quaternion quat1,
const EPhysics_Quaternion quat2,
double  ratio,
EPhysics_Quaternion result 
)

Return the quaternion which is the result of Spherical Linear Interpolation between two quaternions.

Slerp interpolates assuming constant velocity.

Parameters
quat1First quaternion.
quat2Second quaternion.
ratioThe ratio between quat1 and quat2 to interpolate. If ratio = 0, the result is quat1, if ratio = 1, the result is quat2.
resultQuaternion used to store the result. If it's NULL, a new quaternion will be allocated (and should be freed after usage).
Returns
The result of slerp between quat1 and quat2, or NULL on error.

◆ ephysics_quaternion_dot()

EAPI double ephysics_quaternion_dot ( const EPhysics_Quaternion quat1,
const EPhysics_Quaternion quat2 
)

Return the dot product between two quaternions.

Parameters
quat1First quaternion.
quat2Second quaternion.
Returns
The dot product between quat1 and quat2 or 0 on error.

◆ ephysics_quaternion_angle_get()

EAPI double ephysics_quaternion_angle_get ( const EPhysics_Quaternion quat1,
const EPhysics_Quaternion quat2 
)

Return the angle between two quaternions.

Parameters
quat1First quaternion.
quat2Second quaternion.
Returns
The angle between quat1 and quat2 or 0 on error.

◆ ephysics_quaternion_length_get()

EAPI double ephysics_quaternion_length_get ( const EPhysics_Quaternion quat)

Return the length of the quaternion.

Parameters
quatQuaternion to get length of.
Returns
The length of quat or 0 on error.

◆ ephysics_quaternion_length2_get()

EAPI double ephysics_quaternion_length2_get ( const EPhysics_Quaternion quat)

Return the length squared of the quaternion.

Parameters
quatQuaternion to get length of.
Returns
The length of quat or 0 on error.