c – 计算两个3D矢量与恒定加速度对齐所需的转矩?
发布时间:2020-12-16 07:14:14 所属栏目:百科 来源:网络整理
导读:我目前正在为卫星游戏构建简化的反应控制系统,并且需要一种方法来使用该系统将卫星与世界空间坐标中的给定单位方向对齐.因为这是一个游戏模拟,我伪造系统,只是在物体震中周围施加扭矩力. 这很难,因为在我的情况下,扭矩的强度不能改变,它可以打开或关闭.这是
我目前正在为卫星游戏构建简化的反应控制系统,并且需要一种方法来使用该系统将卫星与世界空间坐标中的给定单位方向对齐.因为这是一个游戏模拟,我伪造系统,只是在物体震中周围施加扭矩力.
这很难,因为在我的情况下,扭矩的强度不能改变,它可以打开或关闭.这是完全的力量或没有力量.计算扭矩需要施加的方向相对容易,但是我无法使其完全对齐而不会失去控制并陷入逻辑循环.它需要在恰当的“时间”施加相反的力,以零角速度着陆在目标方向上. 到目前为止我所确定的是,我需要根据当前的角速度和两个矢量之间的角度计算达到零速度所需的“时间”.如果超过我达到零角度的时间,则需要施加相反的扭矩.从理论上讲,这也可以防止它在轴周围“弹跳”太多.我几乎让它工作,但在某些情况下似乎卡在一个方向施加力,所以我希望有人可以检查逻辑.我的模拟目前不考虑质量,因此您可以忽略惯性张量(除非它使计算更容易!) 对于一个轴,我目前正在这样做,但我认为有人会有一个更优雅的解决方案,实际上可以同时计算Yaw和Pitch轴(Roll无效). Omega = Angular Velocity in Local-Space (Degrees Per Second) Force = Strength of the Thrusters // Calculate Time Variables float Angle = AcosD(DotProduct(ForwardVector,DirectionVector)); float Time1 = Abs(Angle / Omega.Z); // Time taken to reach angle 0 at current velocity float Time2 = Abs(DeltaTime * (Omega.Z / Force); // Time it will take to reach Zero velocity based on force strength. // Calculate Direction we need to apply the force to rotate toward the target direction. Note that if we are at perfect opposites,this will be zero! float AngleSign = Sign(DotProduct(RightVector,DirectionVector)); float Torque.Z = 0; if (Time1 < Time2) { Torque.Z = AngleSign * Force; } else { Torque.Z = AngleSign * Force * -1.0f } // Torque is applied to object as a change in acceleration (no mass) and modified by DeltaSeconds for frame-rate independent force. 这远非优雅,肯定有一些标志问题.你们有没有人知道更好的方法来达到这个目的? 编辑: 解决方法
从“计算方向”线开始,您可以直接计算3D中的校正扭矩矢量,如果您知道之前的校正即将超调,则修改其符号:
// Calculate Direction we need to apply the force to rotate toward the target direction Torque = CrossProduct(DirectionVector,ForwardVector) Torque = Normalize(Torque) * Force if (Time2 < Time1) { Torque = -Torque } 但你应该处理有问题的案件: // Calculate Direction we need to apply the force to rotate toward the target direction Torque = CrossProduct(DirectionVector,ForwardVector) if (Angle < 0.1 degrees) { // Avoid divide by zero in Normalize Torque = {0,0} } else { // Handle case of exactly opposite direction (where CrossProduct is zero) if (Angle > 179.9 degrees) { Torque = {0,1} } Torque = Normalize(Torque) * Force if (Time2 < Time1) { Torque = -Torque } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |