При попытке получить дополнительные углы Эйлера из кватерниона мне кажется, что я меняю местами компоненты y и z, но не понимаю, как и почему. Я нахожусь в левой системе координат, и кажется, что кватернион, который я создаю, правильный (проверено здесь), и все, что я прочитал, говорит о том, что моя функция ToEuler является стандартной, согласно моим выводам, я вычисляю ее неправильно
Вывод
In: 90 0 1
Out: 90 1 0
Quaternion (xyzw): 0.70708 0.00617059 0.00617059 0.70708
Код
#include
#define PI_ 3.14159265f
float RadiansToDegrees(float Radians) {
float RadiansToDegrees = (float)(Radians * (180 / PI_));
return RadiansToDegrees;
}
float DegreesToRadians(float Degrees) {
float DegreesToRadians = (float)(Degrees * (PI_ / 180));
return DegreesToRadians;
}
struct Vector3 {
float x;
float y;
float z;
Vector3() { }
Vector3(float x_, float y_, float z_) : x(x_), y(y_), z(z_) { }
};
struct Quaternion {
float x;
float y;
float z;
float w;
void RotationXYZ(Vector3 rotation) {
float halfPitch = rotation.x * 0.5f;
float halfYaw = rotation.y * 0.5f;
float halfRoll = rotation.z * 0.5f;
float sinRoll = sin(halfRoll);
float cosRoll = cos(halfRoll);
float sinPitch = sin(halfPitch);
float cosPitch = cos(halfPitch);
float sinYaw = sin(halfYaw);
float cosYaw = cos(halfYaw);
this->x = (cosYaw * sinPitch * cosRoll) - (sinYaw * cosPitch * sinRoll);
this->y = (sinYaw * cosPitch * cosRoll) + (cosYaw * sinPitch * sinRoll);
this->z = (cosYaw * cosPitch * sinRoll) + (sinYaw * sinPitch * cosRoll);
this->w = (cosYaw * cosPitch * cosRoll) - (sinYaw * sinPitch * sinRoll);
}
Vector3 ToEuler() const {
Vector3 returnVal;
// Compute roll (x-axis rotation)
float sinr_cosp = 2 * (w * x + y * z);
float cosr_cosp = 1 - 2 * (x * x + y * y);
returnVal.x = std::atan2(sinr_cosp, cosr_cosp);
// Compute pitch (y-axis rotation)
float sinp = 2 * (w * y + z * x);
if(std::fabs(sinp) >= 1)
returnVal.y = std::copysign(PI_ / 2, sinp); // use 90 degrees if out of range
else
returnVal.y = std::asin(sinp);
// Compute yaw (z-axis rotation)
float siny_cosp = 2 * (w * z - x * y);
float cosy_cosp = 1 - 2 * (y * y + z * z);
returnVal.z = std::atan2(siny_cosp, cosy_cosp);
return returnVal;
}
};
void main() {
Vector3 inRotation(90.0f, 0.0f, 1.0f);
Quaternion rotationQuat;
rotationQuat.RotationXYZ(Vector3(DegreesToRadians(inRotation.x), DegreesToRadians(inRotation.y), DegreesToRadians(inRotation.z)));
Vector3 outRotation = rotationQuat.ToEuler();
outRotation = Vector3(RadiansToDegrees(outRotation.x), RadiansToDegrees(outRotation.y), RadiansToDegrees(outRotation.z));
std::cout
Подробнее здесь: https://stackoverflow.com/questions/790 ... tract-them
Как я могу преобразовать углы Эйлера в кватернион и извлечь их? ⇐ C++
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Углы Эйлера для ручного преобразования матрицы вращения для устройств iOS
Anonymous » » в форуме IOS - 0 Ответы
- 16 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Углы Эйлера для ручного преобразования матрицы вращения для устройств iOS
Anonymous » » в форуме IOS - 0 Ответы
- 19 Просмотры
-
Последнее сообщение Anonymous
-