bgc-c/docs/quaternion/swap-eng.md

1.6 KiB

Swapping

Русская версия / Russian version

The exchange functions allow two quaternions of the same type to exchange component values.

Function for BGC_FP32_Quaternion:

inline void bgc_fp32_quaternion_swap(BGC_FP32_Quaternion* const quarternion1, BGC_FP32_Quaternion* const quarternion2);

Function for BGC_FP64_Quaternion:

inline void bgc_fp64_quaternion_swap(BGC_FP64_Quaternion* const quarternion1, BGC_FP64_Quaternion* const quarternion2);

The quarternion1 and quarternion2 parameters must be valid pointers. The NULL (0) value is considered invalid.

The quaternion quarternion1 after calling this function will have the same component values the quaternion quarternion2 had before calling the function.

And the quaternion quarternion2 after calling this function will have the same compnent values the quaternion quarternion1 had before calling the function.

Example

#include <stdio.h>
#include <basic-geometry.h>

int main()
{
    BGC_FP32_Quaternion q1, q2;

    bgc_fp32_quaternion_set_values(&q1, 4, -2, 7, 5);
    bgc_fp32_quaternion_set_values(&q2, -5, 10, -1, -3);

    bgc_fp32_quaternion_swap(&q1, &q2);

    printf("Quaternion #1: s = %f, x = %f, y = %f, z = %f\n", q1.s, q1.x, q1.y, q1.z);
    printf("Quaternion #2: s = %f, x = %f, y = %f, z = %f\n", q2.s, q2.x, q2.y, q2.z);

    return 0;
}

The console output:

Quaternion #1: s = -5.000000, x = 10.000000, y = -1.000000, z = -3.000000
Quaternion #2: s = 4.000000, x = -2.000000, y = 7.000000, z = 5.000000

Documentation / Quaternions