Sign in to follow this  

Pendulum... velocity problem

This topic is 4662 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

This topic is 4662 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this