How to calculate the trajectory of an object under rotating thrust?

DangerFace

Apologies if this is the wrong space for this question. I'm a hobbiest programmer working on a 2D video game. I've spent a good amount of time searching for a solution to this online.

I have an object.
I know the mass.
I know the initial velocity.
The environment it is in is frictionless.
The object emits thrust like a rocket from behind itself, but loses no mass.
The force of the thrust is constant, but user defined.
The object is under a constant, but user-defined rotation.

I am trying to find a formula to predict the location of the object, knowing how long it has been under constant rotation and thrust.

The goal is to have the game plot the trajectory as a line so the user knows the probable outcome of their movement orders. Any help or guidance as to where I could find this is greatly appreciated.

Thank you for your time.

romsek

Math Team
The relationship of the spin axis and the thrust vector are going to be rather important on this one.

Do you have this?

DangerFace

DangerFace

Hi Romsek.

I believe I have that. I had look up those terms to be sure.

The object's spin is locked to one axis.

If it were a coin, like a quarter, it would be laying face up on a table. It would rotate around the center of the quarter.

The thrust vector would be in a line that could be drawn through the center of the quarter out past the edge of the quarter. Let's say the thrust is coming out of the edge by the center of the head's neck.

As the quarter rotates, the thrust would continue to come out of that same location on the quarter.

As I am trying to keep the game simple, rotating itself does not change the quarter's velocity at all.

Does that help? I can submit photos or a link to video if the actual movement if that helps.

Math Team
like this?

weirddave

An option is to simply run the code that moves the ship at a greatly increased speed then grab the positions of the ship at regular future points in time and display them as dots at the current time.

DangerFace

@romsek Yeah, just like that. Thank you for taking time to understand/help me with this.

@weirddave Hello. That is a possibility, however my code is using Unity's 2d physics. The research that I have done suggests that I can't run those calculations at increased speed, but I could be wrong. It is also possible to come up with a way to simulate the physics without running them, but the solution I found was resource intensive. The game will ideally be on a phone, so where possible I'm trying to save where I can. If it is possible to find a formula, considering that all the variables are known, it would be the most efficient solution.

romsek

Math Team
You get this.

$\{x(t),y(t)\} = \left\{\dfrac{m vx_0 \omega ^2t -T \cos (\omega t )+T}{m \omega^2},\dfrac{(m vy_0 \omega^2+t T \omega)t -T \sin (\omega t)}{m \omega^2}\right\}$

$m$ is mass of the spaceship
$vx_0$ is any initial velocity in the x direction before rotating thrust cuts in
$vy_0$ is any initial velocity in the y direction before rotating thrust cuts in
$T$ is the magnitude of the thrust
$\omega$ is the radial velocity of the spaceship, i.e. $2\pi$ times the rotations per second.

DangerFace

@romsek Thank you so much! I can work with that!

romsek

Math Team
You get this.

$\{x(t),y(t)\} = \left\{\dfrac{m vx_0 \omega ^2t -T \cos (\omega t )+T}{m \omega^2},\dfrac{(m vy_0 \omega^2+ T \omega)t -T \sin (\omega t)}{m \omega^2}\right\}$

$m$ is mass of the spaceship
$vx_0$ is any initial velocity in the x direction before rotating thrust cuts in
$vy_0$ is any initial velocity in the y direction before rotating thrust cuts in
$T$ is the magnitude of the thrust
$\omega$ is the radial velocity of the spaceship, i.e. $2\pi$ times the rotations per second.
There was an extraneous $t$. Corrected formula is above.

weirddave

@weirddave Hello. That is a possibility, however my code is using Unity's 2d physics. The research that I have done suggests that I can't run those calculations at increased speed, but I could be wrong. It is also possible to come up with a way to simulate the physics without running them, but the solution I found was resource intensive. The game will ideally be on a phone, so where possible I'm trying to save where I can. If it is possible to find a formula, considering that all the variables are known, it would be the most efficient solution.
I'm not terribly familiar with unity. Somewhere in the code there must be a function which updates the current position based on the amount of time passed, normally the time since the last frame.
If you can find that function, I would do something like this:
Code:
While 1 /* assume we're running the main loop forever */
/*update the ship position!*/
Compute_Obj_Position(My_Ship, Frame_Time); /* I've assumed all the pilot controls are contained within the ship object and that the code can actually update the ship object like this, which it probably can't (my C is rusty) */
Ship_Obj Temp_Ship = My_Ship; /*make a copy of the ship in its current state*/
Temp_Ship.visible = false; /*depending if objects are auto drawn, whatever ;) */
for (int i = 1;i < 6;i++){
Compute_Obj_Position(Temp_Ship, 1000); /* move the ship forward in time by 1000ms */
Draw_Obj (Blob_Obj, Temp_Ship.X_pos, Temp_Ship.Y_pos);
}
/* other code here and wait for the current frame time to end (because why run at faster than the screen refresh rate */
}
A slightly better method is to increment the Temp_Ship by whatever the frame rate is (a smaller timestep than 1000ms I would hope!) and pull out the position after each second has passed. It really depends how the position is actually computed as to whether or not the smaller timestep gives a better result, but because it's using the same code, the ship will be where the prediction suggests, which may not be the same as if you use different maths for the prediction.
If the ship position update code uses the same maths that romsek has suggested, you would still call the same function for the prediction blobs, it makes it easier when you make changes. (you may wish to change the update code to do 'proper' maths if it isn't doing so already )

Last edited: