Calculate the torque needed to align two 3D vectors with constant acceleration?

Currently, I am creating a simplified reaction control system for playing in the satellite and I need a way to use the system to coordinate the satellite with a given unit direction in the coordinates of world space. Since this is a game simulation, I fake the system and just apply the force of torque around the epicenter of objects.

This is difficult, because in my case the torque cannot be changed in strength, it is either on or off. This is either full power or no power. Calculation of the direction in which the torque should be applied is relatively simple, but I have problems aligning it without pushing out of control and getting stuck in a logical cycle. he needs to use the opposite force at exactly the right time to land on the target orientation at zero angular speed.

What I have determined so far is that I need to calculate the “time” it takes to reach zero speed based on my current angular speed and the angle between the two vectors. If this exceeds the time until it reaches the zero angle, then it needs to apply the opposite torque. Theoretically, this will also prevent too much "bounce" around the axis. I almost work, but in some cases it seems that he is stuck, using force in one direction, so I hope someone can check the logic. My simulation currently does not take mass into account, so you can ignore the inertia tensor (unless that makes the calculation easier!)

For one axis , I am doing it this way now, but I believe that someone will have a much more elegant solution that can actually calculate the Yaw and Pitch axes right away (Roll is not valid).

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. 

This is far from elegant, and there are certain problems with the symptoms. Do you know what is the best way to achieve this?

EDIT: If someone understands the Unreal Engine Blueprint system, here's how I prototype it now before moving it to C ++

enter image description here

+4
source share
3 answers

Starting from the line “Calculate Direction”, instead, you can directly calculate the torque correction vector in 3D, and then change its sign if you know that the previous correction is about to roll over:

// 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, 0}
}
else
{
  // Handle case of exactly opposite direction (where CrossProduct is zero)
  if (Angle > 179.9 degrees)
  {
    Torque = {0, 0, 1}
  }

  Torque = Normalize(Torque) * Force
  if (Time2 < Time1)
  {
    Torque = -Torque
  }
}
+1

, , , , , , , 0. ( - ) , , 0?

, 0, , 0, .

0

- ? UE4. . . , . , , Z 100 , 0,015 , 0,016 , , . , - - , , .

0

Source: https://habr.com/ru/post/1615385/


All Articles