java 某点 旋转_物体围绕某个点旋转一定角度

转自: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)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值