Skip to main content
gamedev.net
🔒 Locked

3D Motion Simulation

Started by Zavg 0 replies 1.2k views
Original Post
Zavg
Zavg
hi, i try to build a simulation of an object in 3d space. the object is point object with properties like this: p : current position of an object. v : current velocity of an object. f : current force applied on an object. m : object's mass (1 kg) dt : time elapsed since previous step start condition: v = (0, 0, 10) p = (50, 0, 0) at every simulation step (about 0.1 sec) the following calculations are made: dt = GetTimeSinceLastStep() f = CalculateForce() v = v + (f / m) * dt p = p + v * dt the function CalculateForce calculates the current force at every step. let's assume that this function always return force in zx plane, perpendicular to the current velocity toward (0, 0, 0). in such case, object suppose to perform circular motion with constant speed about the origin in zx plane. but here is my problem: [(f/m) * dt] vector (that added to current velocity) will always have some length. so after addition it to v, the new v vector will be longer than the previous one (hypotenuse is always greater than two other sides in triangle). so in my simulation the object always increase it's speed and instead of circular motion i have a spiral one. where is an error ??????? thanx in advance
oliii
oliii
no error, it's how things actually works :)

If you want to a circular motion, you can try to clanmp your velocity to a known value.

const float speed = 10.0f;
f = CalculateForce()
v = v + (f / m) * dt
v.normalise();
v *= speed;
p = p + v * dt

I'm not entirely sure what the end result would be but from intuition, it should circle around a point with a distance being a function of the speed (maybe radius = v / dt?).

if you think of say, a satellite orbiting earth, the only force acting on the satellite is earth's gravity, that pulls the satellite towards earth's centre.

If the satellite has no initial speed, it will just fall towards the ground. If the satellite has an initial speed, the satellite will orbit earth in an elliptic fashion. If you want it to orbit earth in a perfect circle, it's velocity has to be precisely calculated to counteract earth's pull (in short, the satellite's centrifugal force needs to counteract earth's gravity).

If you add friction to the process, the satellite's orbit will start to decay and slowly fall down to earth.
Everything is better with Metal.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.