Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

3D Motion Simulation

  1. Apr 7, 2009 #1

    Zav

    User Avatar

    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 = (0, 0, 0)
    dt = 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 (according to Pythagoras law) the new v vector will be longer than the previous one.

    so in my simulation the object always increase it's speed and instead of cirlular motion a have a spiral one.

    where is an error ???????

    thanx in advance :)
    the new
     
  2. jcsd
  3. Apr 7, 2009 #2

    Born2bwire

    User Avatar
    Science Advisor
    Gold Member

    Force is a vector. For circular motion, you need to have the force always pointing towards the center of the circle of motion, the centripetal force. This force has to have a specific relation to your initial velocity for you to actually have the object move in a circle. So you should expect to get a force of constant magnitude.
     
  4. Apr 8, 2009 #3
    If you are working in a two dimensional plane, you should work with two forces, one in z direction and one in x direction. Your program should more or less look like this

    f_x = CalculateForceX()
    f_z = CalculateForceZ()
    v_x = v_x + (f_x / m) * dt
    v_z = v_z + (f_z / m) * dt
    p_x = p_x + v_x* dt
    p_z = p_z + v_z* dt

    the relations for the force would be something equivalent to f_x = -F*cos(phi) and f_z = -F*sin(phi). Phi is the angle between the x-axis and the current place of your mass in counterclockwise direction. F is the centrifugal force, directed to the center, this should counter the centripetal force, this is m*V^2/r if I remember correctly, with V it's total speed and r the distance to the center.
     
    Last edited: Apr 8, 2009
  5. Apr 8, 2009 #4
    If you're using an OOP, I suggest making a vector class. If you're using C++ specifically, you can overload operators, so that instead of writing

    v_x = v_x + (f_x / m) * dt
    v_y = v_y + (f_y / m) * dt
    v_z = v_z + (f_z / m) * dt

    you just write

    v = v + f/m * dt;
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook