카테고리 없음

[FDF] 짐벌락 gimbal lock 오일러

90도가 되었을때 짐벌락 현상이 일어나 버린다 

 

 

 

 

오일러 변환을 이용한 것

    printf("%f %f %f\n", ft_sin(param.angle.x), ft_sin(param.angle.y), ft_sin(param.angle.z));
    printf("%f %f %f\n", ft_cos(param.angle.x), ft_cos(param.angle.y), ft_cos(param.angle.z));
    x 
    dot.y = ft_cos(param.angle.x) * dot.y - ft_sin(param.angle.x) * dot.z;
    dot.z = ft_sin(param.angle.x) * dot.y + ft_cos(param.angle.x) * dot.z;
    y
    dot.x = ft_cos(param.angle.y) * dot.x + ft_sin(param.angle.y) * dot.z;
    dot.z = -ft_sin(param.angle.y) * dot.x + ft_cos(param.angle.y) * dot.z;
    z
    dot.x = ft_cos(param.angle.z) * dot.x - ft_sin(param.angle.z) * dot.y;
    dot.y = ft_sin(param.angle.z) * dot.x + ft_cos(param.angle.z) * dot.y;

이 현상에 문제가 생겨서 

쿼터니언 (사원수 코드로 변경해야 할거 같다 좀더 공부해야겟다

https://eater.net/quaternions

 

Visualizing quaternions, an explorable video series

Explaining how quaternions, a four-dimensional number system, describe 3d rotation.

eater.net

여기서 작동 방법을 볼수 있다

 

자세한 식은 여기

https://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles

 

Conversion between quaternions and Euler angles - Wikipedia

From Wikipedia, the free encyclopedia Jump to navigation Jump to search Spatial rotations in three dimensions can be parametrized using both Euler angles and unit quaternions. This article explains how to convert between the two representations. Actually t

en.wikipedia.org

 

 

즉 한차원 더 올라가서 계산을 해야한다는 건데 음 4차원 만든다는 레이어 부터 이거 설명글 쓰기가 넘어렵다

struct Quaternion
{
    double w, x, y, z;
};

Quaternion ToQuaternion(double yaw, double pitch, double roll) // yaw (Z), pitch (Y), roll (X)
{
    // Abbreviations for the various angular functions
    double cy = cos(yaw * 0.5);
    double sy = sin(yaw * 0.5);
    double cp = cos(pitch * 0.5);
    double sp = sin(pitch * 0.5);
    double cr = cos(roll * 0.5);
    double sr = sin(roll * 0.5);

    Quaternion q;
    q.w = cr * cp * cy + sr * sp * sy;
    q.x = sr * cp * cy - cr * sp * sy;
    q.y = cr * sp * cy + sr * cp * sy;
    q.z = cr * cp * sy - sr * sp * cy;

    return q;
}

일단 위에서 제공하는 식이다

음 yaw pit