Orientation and angle displacement in 3D (8)

Source: Internet
Author: User

Convert from orah to Quaternary

To convert the angle displacement from the Euclidean angle to the Quaternary angle, you can use a method similar to the Euclidean angle matrix. First, convert the three rotations to the four elements. This is a simple operation. Then, we concatenate these three Enis into one. Like a matrix, there are two situations to consider. The first is inertia-Object four-element, and the second is the object-inertial four-element. Because they are mutually bounded, we only derive the inertia-object Quaternary.

Set ouarla to variables H, P, and B.H,P,BRound-axis Y, X, and Z. Remember, use negative rotation because they specify the rotation angle in the coordinate system.

Connect them in the correct order to get the formula 10.24:

(Remember, the four-element multiplication is defined as multiplication from left to right in the order of rotation .)

The object-inertial four-element is the inertia-the object's four-element concatenation. For details, see formula 10.25:

 

Convert from the Quaternary element to the ouarla corner

Based on the previous formula, we found that:

Now you can directly convert it to the code, as shown in program list 10.5, which converts inertia-object Quaternary element into a euclidean angle.

Listing 10.5: converting an inertial-to-object Quaternion to Euler Angles

// Use global variables for Input and Output
Float w, x, y, z;
Float H, P, B;

// Extract sin (pitch)
Float sp =-2.0f * (y * z + W * X );

// Check for gimbal lock, giving slight tolerance for numerical impretries
If (FABS (SP)> 0.9999f ){
// Looking straight up or down
P = 1.570796f * sp; // PI/2

// Compute heading, slam bank to zero
H = atan2 (-x * z-W * y, 0.5f-y * Y-z * z );
B = 0.0f;
} Else {
// Compute angles
P = Asin (SP );
H = atan2 (x * z-W * y, 0.5f-x * x-y * y );
B = atan2 (x * Y-W * z, 0.5f-x * X-z * z );
}

The code used to convert an object, the inertial four-element, to the Euclidean angle is very similar to that used above. Only the values of X, Y, and Z are changed to negative values, because the object-inertial four-element is inertial-the object's four-element concatenation.

Listing 10.6: converting an object-to-inertial Quaternion to Euler Angles

// Extract sin (pitch)
Float sp =-2.0f * (y * z-W * X );

// Check for gimbal lock, giving slight tolerance for numerical impretries
If (FABS (SP)> 0.9999f ){
// Looking straight up or down
P = 1.570796f * sp; // PI/2

// Compute heading, slam bank to zero
H = atan2 (-x * z + W * y, 0.5f-y * Y-z * z );
B = 0.0f;
} Else {
// Compute angles
P = Asin (SP );
H = atan2 (x * z + W * y, 0.5f-x * x-y * y );
B = atan2 (x * Y + W * z, 0.5f-x * X-z * z );
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.