Orientation and angle displacement in 3D (6)

Source: Internet
Author: User
Tags asin

Quaternary splines ---- "squad"

Slerp provides interpolation between two orientations. What if there are more than two azimuth sequences (which describe the interpolation path we want to go through? We can use slerp between control points. Similar to linear interpolation in basic geometry, the control points are connected in a straight line. Obviously, there will be discontinuity on the control point-this is what we want to avoid. We give the squad (spherical and quadrangle) formula to depict the path between control points.

The control point is defined by the Quaternary sequence:

Q1,Q2,Q3 ,...QN-2,QN-1,QN

In addition, an auxiliary Quaternary element is introduced.SI, use it as a temporary control point:

Note,QI-1QI + 1 calculatesSI, soS1 andSN is undefined. In other words, the curve fromQ2 extendQN-1, the first and last control points are only used to control the curve in the middle. If the curve must go through these two points, virtual control points must be added at the header and tail. An obvious way is to copy the two control points.

Given four adjacent control points, squad is used to calculate the interpolation between two points in the middle, which is very similar to cubic spline.

Set four control points:QI-1,QI,QI + 1,QI + 2

Also introduce an interpolation variable H, H from 0 to 1, squad depictsQIQThe curve between I + 1.

The squad method can be used to obtain the entire Interpolation curve, as shown in formula 10.12:

 

Advantages and disadvantages

There are some other advantages of the method for expressing the angle displacement of the Quaternary element:

(1) smooth interpolation. Slerp and squad provide smooth interpolation between orientations, and there is no other method to provide smooth interpolation.

(2) Calculate the inverse of the fast connection and the angle displacement. Using a matrix to perform the same operation will be much slower. It provides an effective method for calculating the antiangular displacement by using the transpose rotation matrix. However, it is not as easy as the Quaternary element.

(3) Fast conversion between products and matrices. The conversion between the Quaternary element and the matrix is a little faster than that between the Euclidean element and the matrix.

(4) use only four numbers. Only four numbers are contained in the Quaternary element, and nine numbers are used in the matrix. It is much more economical than the matrix (of course, it is still 33% more than the Euclidean value ).


To achieve these advantages, we have to pay the price. There are also problems similar to the matrix, but the problem is mild:

(1) It is a little larger than ouarla. This extra number does not seem to have much to do with it, but when you need to save a large amount of angular displacement, such as storing animated data, this additional 33% is also a considerable amount.

(2) The Quaternary element may be invalid. The accumulation of bad input data or floating-point number rounding errors can make the four-dimensional element invalid (this problem can be solved through the standardization of the Four-dimensional element to ensure that the four-dimensional element is the unit size ).

(3) difficult to use. In all three forms, the Quaternary element is the most difficult to use directly.

 

Comparison of Methods

 

The representation of different orientations is applicable to different situations. Below are some suggestions for choosing a proper format:

(1) ouarla is the easiest to use. When you need to specify the orientation of an object in the world, the orah angle can greatly simplify human-computer interaction, including entering the orientation directly on the keyboard and specifying the orientation in the Code (for example, setting the camera for rendering), testing in debugging. This advantage should not be ignored. Do not sacrifice usability in the name of optimization unless you are sure that this optimization is indeed effective.

(2) If you need to convert the vector between coordinate systems, select the matrix form. Of course, this does not mean that you cannot store the orientation in other formats and convert it to the matrix form as needed. Another method is to use the Euclidean angle as the primary copy of the azimuth, but maintain a rotating matrix at the same time. When the Euclidean angle changes, the matrix must be updated at the same time.

(3) When you need to store a large amount of orientation data (such as animation), you can use the Euler's angle or quaternary element. Ouarla will occupy less than 25% of the memory, but it will be a little slower when converting to a matrix. If the animation data needs to be connected between nested coordinate systems, it may be the best choice to use the Quaternary element.

(4) smooth interpolation can only be completed using a quaternary number. If you use another format, you can also convert it to the Quaternary element before interpolation. After interpolation, you can convert it back to the original format.

 

 

Convert from orah to Matrix

Orah angles describe a rotation sequence. Calculate each rotating matrix and connect them into a matrix. This matrix represents the entire angle displacement. Of course, it is related to the transformation matrix from an object to an inertial coordinate or the transformation matrix from an inertial to an object coordinate.

We define a rotation sequence to convert an object (and its coordinate space) from the inertial coordinate space to the object coordinate space. Therefore, you can use the direct conversion defined by the ouarla corner to directly generate inertia-the general form of the object rotation matrix:

MInertia --> Object =HPB

H,P,BThey are the rotation matrices of heading, pitch, and bank. They rotate around y, X, and Z axes respectively. Only rotating the "coordinate space" is the exact opposite operation of rotating the "point. We can imagine that the rotation time point remains unchanged in the space. For example, pitch causes the coordinate space to go down, and the point actually relates to the coordinate space to go up. The Euclidean formula clearly indicates that an object and its coordinate space are rotated, but what we need is to transform the matrix of "points", so the calculation matrixH,P,BThe Opposite rotation quantity is used for rotation. Set heading, pitch, and bank rotation angles as variables H, P, and B:

 

Connect these matrices in proper order to obtain the formula 10.21:

If you want to transform from an object's coordinate space to an inertial coordinate space, you should use the inertia-inverse of the object's rotation matrix. Because the rotation matrix is orthogonal, the inverse of the rotation matrix is to find its transpose. The following describes how to verify this.

In order to transform from the coordinate space of an object to the inertial coordinate space, the order should be "un-Bank", "un-pitch", and "un-heading". The formula is:

MObject> inertia = (MInertia-> Object)-1 = (HPB)-1 =B-1P-1H-1

Note that the rotation matrix can be consideredB-1,P-1,H-1 is the inverse of their corresponding matrices, or a general rotation matrix using the opposite rotation angles B, P, and H. (Inertia-the negative rotation angle is used in the object matrix, so the angle here does not need to be changed to negative .)

Connect these matrices in proper order to obtain the formula 10.22:

By comparing formula 10.21 and formula 10.22, we can see that the object-the inertial matrix is indeed inertial-the transpose of the object matrix.

 

Transition from matrix to ouarla

The following points need to be taken into account to convert the angle displacement from matrix form to the orah angle:

(1) It is necessary to know what rotation the matrix represents: the object-inertia or inertia-the object. Here we will discuss the technology of using inertia-the object matrix, the process of converting an object-inertial matrix into an ouararche is similar to that of conversion.

(2) For any given angle displacement, there are infinite number of orazs that can be used to represent it. Because of the problem of "alias", the technology discussed here always returns the range of "restrict oura corner", heading and bank: ± 180 °, and pitch: ± 90 °.

(3) The matrix may be pathological. We must endure the error of floating point precision. Some matrices also include transformations except rotation, such as scaling and mirroring. Here we only discuss the transformations that work on the rotating matrix.

After taking these factors into consideration, we try to get the ouarla corner from formula 10.21:


If cos p = 0, then we cannot use the above trick since all the matrix elements involved are zero.
However, notice that when Cos p = 0, then p = 90 °, which means we are either looking straight
Up or straight down. This is the gimbal lock situation, where heading and bank limit tively rotate
About the same physical axis (the vertical axis). In this case, we will arbitrarily assign all Rotation
About the vertical axis to heading and set Bank equal to zero. Now we know the value of pitch and
Bank, and all we have left is to solve for heading. Armed with the following simplifying
Assumptions:

COSP = 0

B = 0

Sinb = 0

CoSb = 1

Place them in formula 10.21:

 

Now, we can calculate H through-m31 and M11, which contain sin and cos values of h respectively.

Let's take a look at the code that uses the above technique to extract the ouarla corner from the inertia-object rotation matrix. To make the example simple, assume that the input and output are global variables.

Listing 10.3: extracting Euler angles from an inertial-to-object rotation matrix

// Assume the matrix is stored in these variables:
Float M11, M12, M13;
Float m21, m22, M23;
Float m31, M32, M33;

// We will compute the Euler angle values in radians and store them here:
Float H, P, B;

// Extract pitch from M23, being careful for domain errors with asin (). We coshould have
// Values slightly out of range due to floating point arithmetic.
Float sp =-M23;

If (sp <=-1.0f ){
P =-1.570796f; //-PI/2
} Else if (SP >=1.0 ){
P = 1.570796; // PI/2
} Else {
P = Asin (SP );
}

// Check for the gimbal lock case, giving a slight tolerance
// For numerical impretries
If (SP> 0.9999f ){
// We are looking straight up or down.
// Slam bank to zero and just set heading
B = 0.0f;
H = atan2 (-m31, m11 );
} Else {
// Compute heading from M13 and M33
H = atan2 (M13, M33 );

// Compute bank from m21 and m22
B = atan2 (m21, m22 );
}

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.