Physics question

Ok, given position, speed, direction and rate of turning, how can I calculate the position of the object at some point in the future?

Is the rate of turning a constant (over a given time interval)? If not, it can get a little complicated.

[This message has been edited by DFrey (edited 08-14-2001).]

Also is this 2D or 3D motion? Also where is the center of the turn? If this is 3D motion, it would make things easier if you know what the turning axis is as well.

Yeah, I probably should of said that in the question. Speed & turning are constant. It’s 2d motion: ignore the y-coordinate. Turning only occurs on the XZ plane.

Ok, then its relatively simple:
Here is some sample code that does that, you can pick out the important parts.

#include <math.h>
#include

using namespace std;

const double pi=3.14159265;

int main(int num, char *cmd)
{
double x0[2],x1[2],v[2],xp[2],w;
double r[2],n[2],radius,theta0,theta1;

// try out a sample condition

double t=1; // t: time interval in seconds

w=pi; //w: turning rate in radians per second
x0[0]=x0[1]=0; //x0: initial position
// v: inital velocity
v[0]=0;
v[1]=3*pi;

double s;
s=(w==0)?0:((w<0)?-1:1);
if(s==0)
{
// linear motion
x1[0]=x0[0]+v[0]t;
x1[1]=x0[1]+v[1]t;
}
else
{
// circular motion
double vmag=s
sqrt(v[0]v[0]+v[1]v[1]);
n[0]=-v[1]/vmag;
n[1]=v[0]/vmag;
radius=vmag/w;
r[0]=x0[0]+radius
n[0];
r[1]=x0[1]+radius
n[1];
xp[0]=x0[0]-r[0];
xp[1]=x0[1]-r[1];
theta0=atan2(xp[1],xp[0]);
theta1=theta0+w
t;
x1[0]=r[0]+radiuscos(theta1);
x1[1]=r[1]+radius
sin(theta1);
}

cout << "Final position " << x1[0] << " " << x1[1] << endl;

return 0;
}

Of course you also have to add code to handle the case when vmag=0.

[This message has been edited by DFrey (edited 08-15-2001).]

Thanks! I don’t exactly understand all of it, but the results seem to make sense and movement looks smoother now

Hi !

Where can I find such code ??(book,pdf-file … ??)

mfg dominik

I do not know offhand, I cooked that code up myself on the spur of the moment (my physics degree proved helpful for once ). It has a lot of room for improvement too.

But if you are looking for general physics routines, a search engine should point the way.

DFrey!
Could you think of a way in 3d incorporating roll and drift? It must have something to do with spirals, but my current physics teacher couldn’t tell me how to do it. I ended up slicing it into small time periods of linear motion (actually per frame… ), but I would think that this would lead to a slightly bigger radius than the realistic movement. Thanks!

Do you know any linear algebra? You ought to be able to use a forward vector, an up vector, velocities for each, and a rotation matrix for all of this. if you use the rotation matrix and you only have 1 angular velocity then i think it will cut down on the amount of computations the CPU has to do in each frame. i can help you with this if you don’t know how to do it.

I’m actually able to do it in linear steps. Means, the camera rotates appropriately to the duration of the last frame, moves a step (one frame) and then again. That’s no problem if you mean that. I’m actually talking about a spiral-like curve. Maybe I got you wrong. Any help is welcome!