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

本文详细介绍了如何在二维平面上使一个点围绕另一个点旋转的数学公式,并进一步探讨了三维空间中点围绕特定轴旋转的复杂过程。通过实例展示了在不同旋转顺序下,如先沿x轴再沿y轴旋转,点的位置变化。同时,文章还提供了在UE4中实现点旋转的具体代码示例。
部署运行你感兴趣的模型镜像

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)

您可能感兴趣的与本文相关的镜像

ComfyUI

ComfyUI

AI应用
ComfyUI

ComfyUI是一款易于上手的工作流设计工具,具有以下特点:基于工作流节点设计,可视化工作流搭建,快速切换工作流,对显存占用小,速度快,支持多种插件,如ADetailer、Controlnet和AnimateDIFF等

### 实现Unity 2D 物体绕指定旋转 为了使 Unity 中的 2D 对象围绕特定进行旋转,可以采用变换矩阵来调整对象的位置和角度。下面是一个具体的解决方案以及相应的代码示例。 #### 使用Transform.RotateAround方法 Unity 提供了 `Transform.RotateAround` 方法可以直接用于让游戏对象绕着任意给定按一定方向转动[^1]。此函数接收三个参数:目标位置(Vector3),轴向量(Vector3),以及旋转角度(float)。 ```csharp using UnityEngine; public class RotateObject : MonoBehaviour { public Transform targetPoint; // 绕转中心 public float speed = 5f; void Update() { if (targetPoint != null) { transform.RotateAround(targetPoint.position, Vector3.forward, Time.deltaTime * speed); } } } ``` 上述脚本定义了一个公共变量 `targetPoint` 来表示作为旋转中心的目标,并通过 `speed` 控制旋转速度。在每一帧更新时调用 `RotateAround()` 函数完成旋转操作。 #### 自定义旋转逻辑 如果希望更灵活地控制旋转行为,则可以通过手动计算新的坐标来进行自定义处理: ```csharp void CustomRotate(Transform objToMove, Vector3 pointOfRotation, float angleDegPerSec) { float angleRad = Mathf.Deg2Rad * angleDegPerSec * Time.deltaTime; Quaternion rotationOffset = Quaternion.Euler(0, 0, angleRad); Vector3 offset = objToMove.position - pointOfRotation; Vector3 rotatedOffset = rotationOffset * offset; objToMove.position = pointOfRotation + rotatedOffset; objToMove.rotation *= rotationOffset; } ``` 这段代码实现了相同的效果——即让物体按照设定的速度围绕某个固定做圆周运动;不过它允许开发者进一步定制化旋转过程中的细节。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值