物体围绕某个点旋转一定角度
Posted 智慧 + 毅力 = 无所不能
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了物体围绕某个点旋转一定角度相关的知识,希望对你有一定的参考价值。
转自:https://dawnarc.com/2016/06/ue4%E7%BA%BF%E6%80%A7%E4%BB%A3%E6%95%B0%E7%89%A9%E4%BD%93%E5%9B%B4%E7%BB%95%E6%9F%90%E4%B8%AA%E7%82%B9%E6%97%8B%E8%BD%AC%E4%B8%80%E5%AE%9A%E8%A7%92%E5%BA%A6/
2D上的点围绕某另一个点旋转: If you rotate point (px, py) around point (ox, oy) by angle theta you’ll get:
p‘x = cos(theta) * (px-ox) - sin(theta) * (py-oy) + ox
p‘y = sin(theta) * (px-ox) + cos(theta) * (py-oy) + oy
this is an easy way to rotate a point in 2D.
=======================================http://stackoverflow.com/questions/13275719/rotate-a-3d-point-around-another-one Try to use vector math. decide in which order you rotate, first along x, then along y perhaps.
If you rotate along z, [z’ = z]
x‘ = x*cos a - y*sin a;
y‘ = x*sin a + y*cos a;
The same repeated for y-axis: [y‘‘ = y‘]
x‘‘ = x‘*cos b - z‘ * sin b;
z‘‘ = z‘*sin b + x‘ * cos b;
Again rotating along x-axis: [x‘‘‘ = x‘‘]
y‘‘‘ = y‘‘ * cos c - z‘‘ * sin c
z‘‘‘ = z‘‘ * sin c + y‘‘ * cos c
And finally the question of rotating around some specific “point”:
First subtract the point from the coordinates, then apply the rotations and finally add the point back to the result.
The problem, as far as I see, is a close relative to “gimbal lock”. The angle w_ny can’t be measured relative to the fixed xyz -coordinate system, but to the coordinate system that is rotated by applying the angle w_nx.
As kakTuZ observed, your code converts point to spherical coordinates. There’s nothing inherently wrong with that – with longitude and latitude one can reach all the places in Earth. And if one doesn’t care about tilting the Earth equatorial plane relative to it’s trajectory around the Sun, it’s ok with me.
The result of not rotating the next reference axis along the first w_ny is that two points that are 1 km a part of each other at equator, move closer each other at the poles and at latitude of 90 degrees, they touch. Even though the apparent purpose is to keep them 1 km apart where ever they are rotated.
================================== UE4中的实现方式
FVector A;
FVector B;
FRotator C;
A点绕B点旋转C之后的坐标:
B+C.RotateVector(A-B)
其他参考: Quaternions and spatial rotationhttps://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation
Rotation matrix https://en.wikipedia.org/wiki/Rotation_matrix#Basic_rotations
以上是关于物体围绕某个点旋转一定角度的主要内容,如果未能解决你的问题,请参考以下文章