Pendulum... velocity problem

Started by
8 comments, last by Squirm 19 years, 1 month ago
Hi buddies! I am writing a simple pendulum simulation using physical equations. Theoretically everything should work fine but practically the pendulum doesn't work as it was designed to... the app is here. I guess the problem is located in velocity vector but I don't know how to fix it because I am convinced that the equations I use are true. Can someone tell me where is the source of the problem? How I get all values is displayed on this image. ...and in this code:

vec g = {0,-1,0}; // gravity force
vec p = {0,0,-4}; // origin coords
vec t;
 
void Process()
{
	t = p - r; // r - point(oscilating) coords
	a = g + (t * cosinus(t,g) * -g.length()); // gets the net force
	v = v + a;
	r = r + v;
}

float vec::length()
{
	return (float)sqrt((x * x) + (y * y) + (z * z));
}

float cosinus(vec a, vec b)
{
	return (float)(((a.x * b.x) + (a.y * b.y) + (a.z * b.z)) / (a.length() * b.length()));
}

Thanks in advance.
"I don't believe in a god that i need to worship"
Advertisement
Well - assuming a, v and r are acceleration, velocity, and position, then

v = v + a*dt;
r = r + v*dt;

where dt is the time increment that you made. Good luck.
would this be good?
	a = g + (t * cosinus(t,g) * -g.length());	v = v + (a * (Timer.f_Time - Timer.f_OldTime));	r = r + (v * (Timer.f_Time - Timer.f_OldTime));

where Timer is used to make the app running at constant speed. I am using QueryPerformanceCounter functions.
"I don't believe in a god that i need to worship"
looks like it should work better?
unfortunatelly still the object moves just like in the app posted above.
After analyzing the movement I found out that the velocity is pushing the object down and that's why the movement is so strange, i dont know how to fix this... Am I missing any force? Maybe impetus?
"I don't believe in a god that i need to worship"
Since your pendulum is always travelling perpendiular to the point of the arc at which you perform the calculation, it will always try to travel 'outwards', because you are calculating the tension for time T and then assuming it will still be the same value at time T + dT at the end of the time step. In other words, you are doing euler intergration and the errors are always in the same general direction, so they build up.

Now, I haven't run the exe, so I don't know if this is _THE_ problem, but it is _A_ problem. You might take a look at the Runge Kutta thread that's been running recently, or even just try implicit or midpoint euler integration instead of the explicit form you have above.
well i know using integrations and other good ways in finding true equations is quite common but wouldn't it be more realistic the way I am solving it? While studying physics on my university i have learned that every movement depends on forces. But if I am wrong then fix me :P
"I don't believe in a god that i need to worship"
Quote:r = r + (v * (Timer.f_Time - Timer.f_OldTime));


That is an integration of velocity over time. It's an Euler integration, and so it is so simple you can barely tell. Does that make my previous post make more sense?
hm... well i thought it's a derivative. Anyway am I missing any force?
"I don't believe in a god that i need to worship"
No, no extra forces are needed. You said earlier that:

Quote:After analyzing the movement I found out that the velocity is pushing the object down and that's why the movement is so strange


If you imagine at any point you calculate exactly the right velocity, and then multiply it by a time step, you will get a straight line, which is added to the position. If you imagine the actual line you should follow, it is a curve. The error you get, in the case of a pendulum, will always be in the same general direction (away from the pivot point) and so will look like a force pushing you downwards. I've tried to draw it incase it helps.

This topic is closed to new replies.

Advertisement