The coordinates of a new point in a three-dimensional space after a point is rotated around a vector

Source: Internet
Author: User
Tags cos sin

In three-dimensional space, a point around the x-axis y-axis z-axis rotation of a certain radian after the coordinates of the new point is easy to calculate, the problem is if it is the rotation axis is an arbitrary vector (x, y, z), how to know the rotation of angle radian after the new point coordinates it.

In OpenGL there is a function Glrotatef (ANGLE,X,Y,Z) that implements this function, and its implementation is to multiply the left by a matrix


It is assumed that the axes are right-handed (OpenGL axes are right-handed, as in the university math textbook), where c = cos (angle), s = sin (angle), Angle's positive or negative is the same, that is, in the right-hand system, the thumb points to the vector direction, The remaining four refers to the angle of the natural surround in the counterclockwise direction, the vector (x, y, z) must be already flat and pass through the origin, so that it can be calculated as:

new_x = (x2 (1-c) +c) * old_x + (XY (1-c)-zs) * old_y + (XZ (1-c) +ys) * Old_z

New_y = (YX (1-c) +zs) * old_x + (y2 (1-c) +c) * old_y + (YZ (1-c)-xs) * Old_z

New_z = (XZ (1-c)-ys) * old_x + (YZ (1-c) +xs) * old_y + (Z2 (1-c) +c) * Old_z

(old_x,old_y,old_z) is the coordinates of the original point, (new_x,new_y,new_z) is the coordinates of the new point after the rotation

How this formula is deduced is not described here, one method is to transform a vector into a coordinate system by the left-multiply rotation matrix m, such as Z, and then rotate around the z-axis that angle equivalent to the left multiply a matrix, and finally the vector left multiply M's inverse matrix to change back, The result of this series of matrix multiplication is the matrix above. This question puzzled me for a long time, such as a vector around a vector rotation at a certain angle to get a new vector is what, use it to calculate, you can calculate the starting point of the vector and the end of the rotation of the new point of the coordinates, and then get a new vector.

It is also a convenient way to solve this problem by using four-dollar number. A four-dollar q= (x, y, z) sin (θ/2), cos (Θ/2)) used to perform the rotation, where the inverse of Q is R, then r= ((-x,-y,-z) sin (θ/2), cos (Θ/2)), the point p to be rotated is p= ((x, Y, z), 0) with a four-dollar number, Here (x, Y, z) is the unit vector, θ is the angle of rotation, (x, Y, z) is the coordinates of P point, the rotated P ' =q*p*r, the multiplication of four-tuple can refer to Grassmann product


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.