quaternion_math_functions.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /******************************************************************************
  2. * @file quaternion_math_functions.h
  3. * @brief Public header file for NMSIS DSP Library
  4. * @version V1.10.0
  5. * @date 08 July 2021
  6. *
  7. * Target Processor: RISC-V Cores
  8. ******************************************************************************/
  9. /*
  10. * Copyright (c) 2010-2021 Arm Limited or its affiliates. All rights reserved.
  11. * Copyright (c) 2019 Nuclei Limited. All rights reserved.
  12. *
  13. * SPDX-License-Identifier: Apache-2.0
  14. *
  15. * Licensed under the Apache License, Version 2.0 (the License); you may
  16. * not use this file except in compliance with the License.
  17. * You may obtain a copy of the License at
  18. *
  19. * www.apache.org/licenses/LICENSE-2.0
  20. *
  21. * Unless required by applicable law or agreed to in writing, software
  22. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  23. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  24. * See the License for the specific language governing permissions and
  25. * limitations under the License.
  26. */
  27. #ifndef QUATERNION_MATH_FUNCTIONS_H_
  28. #define QUATERNION_MATH_FUNCTIONS_H_
  29. #include "riscv_math_types.h"
  30. #include "riscv_math_memory.h"
  31. #include "dsp/none.h"
  32. #include "dsp/utils.h"
  33. #ifdef __cplusplus
  34. extern "C"
  35. {
  36. #endif
  37. /**
  38. * @defgroup groupQuaternionMath Quaternion Math Functions
  39. * Functions to operates on quaternions and convert between a
  40. * rotation and quaternion representation.
  41. */
  42. /**
  43. @brief Floating-point quaternion Norm.
  44. @param[in] pInputQuaternions points to the input vector of quaternions
  45. @param[out] pNorms points to the output vector of norms
  46. @param[in] nbQuaternions number of quaternions in each vector
  47. */
  48. void riscv_quaternion_norm_f32(const float32_t *pInputQuaternions,
  49. float32_t *pNorms,
  50. uint32_t nbQuaternions);
  51. /**
  52. @brief Floating-point quaternion inverse.
  53. @param[in] pInputQuaternions points to the input vector of quaternions
  54. @param[out] pInverseQuaternions points to the output vector of inverse quaternions
  55. @param[in] nbQuaternions number of quaternions in each vector
  56. */
  57. void riscv_quaternion_inverse_f32(const float32_t *pInputQuaternions,
  58. float32_t *pInverseQuaternions,
  59. uint32_t nbQuaternions);
  60. /**
  61. @brief Floating-point quaternion conjugates.
  62. @param[in] pInputQuaternions points to the input vector of quaternions
  63. @param[out] pConjugateQuaternions points to the output vector of conjugate quaternions
  64. @param[in] nbQuaternions number of quaternions in each vector
  65. */
  66. void riscv_quaternion_conjugate_f32(const float32_t *inputQuaternions,
  67. float32_t *pConjugateQuaternions,
  68. uint32_t nbQuaternions);
  69. /**
  70. @brief Floating-point normalization of quaternions.
  71. @param[in] pInputQuaternions points to the input vector of quaternions
  72. @param[out] pNormalizedQuaternions points to the output vector of normalized quaternions
  73. @param[in] nbQuaternions number of quaternions in each vector
  74. */
  75. void riscv_quaternion_normalize_f32(const float32_t *inputQuaternions,
  76. float32_t *pNormalizedQuaternions,
  77. uint32_t nbQuaternions);
  78. /**
  79. @brief Floating-point product of two quaternions.
  80. @param[in] qa First quaternion
  81. @param[in] qb Second quaternion
  82. @param[out] r Product of two quaternions
  83. */
  84. void riscv_quaternion_product_single_f32(const float32_t *qa,
  85. const float32_t *qb,
  86. float32_t *r);
  87. /**
  88. @brief Floating-point elementwise product two quaternions.
  89. @param[in] qa First array of quaternions
  90. @param[in] qb Second array of quaternions
  91. @param[out] r Elementwise product of quaternions
  92. @param[in] nbQuaternions Number of quaternions in the array
  93. */
  94. void riscv_quaternion_product_f32(const float32_t *qa,
  95. const float32_t *qb,
  96. float32_t *r,
  97. uint32_t nbQuaternions);
  98. /**
  99. * @brief Conversion of quaternion to equivalent rotation matrix.
  100. * @param[in] pInputQuaternions points to an array of normalized quaternions
  101. * @param[out] pOutputRotations points to an array of 3x3 rotations (in row order)
  102. * @param[in] nbQuaternions in the array
  103. *
  104. * <b>Format of rotation matrix</b>
  105. * \par
  106. * The quaternion a + ib + jc + kd is converted into rotation matrix:
  107. * a^2 + b^2 - c^2 - d^2 2bc - 2ad 2bd + 2ac
  108. * 2bc + 2ad a^2 - b^2 + c^2 - d^2 2cd - 2ab
  109. * 2bd - 2ac 2cd + 2ab a^2 - b^2 - c^2 + d^2
  110. *
  111. * Rotation matrix is saved in row order : R00 R01 R02 R10 R11 R12 R20 R21 R22
  112. */
  113. void riscv_quaternion2rotation_f32(const float32_t *pInputQuaternions,
  114. float32_t *pOutputRotations,
  115. uint32_t nbQuaternions);
  116. /**
  117. * @brief Conversion of a rotation matrix to equivalent quaternion.
  118. * @param[in] pInputRotations points to an array 3x3 rotation matrix (in row order)
  119. * @param[out] pOutputQuaternions points to an array of quaternions
  120. * @param[in] nbQuaternions in the array
  121. */
  122. void riscv_rotation2quaternion_f32(const float32_t *pInputRotations,
  123. float32_t *pOutputQuaternions,
  124. uint32_t nbQuaternions);
  125. #ifdef __cplusplus
  126. }
  127. #endif
  128. #endif /* ifndef _QUATERNION_MATH_FUNCTIONS_H_ */