locked
Physics Engine RRS feed

  • General discussion

  • Hi there guys!

    I thought I should start a new discussion to talk about and improve a physics engine im currently working on.

    Here's the current version: DZH677 (I took out the wall collision check. I want to concentrate on that later.)

    I guess the next step is to add physically correct rotation. I mean the decision on wich side to start rotating.

    I guess you'll have to think a vertical line going through the corner which is touching the ground. Then start rotating on the side which has more mass.

    Something like this:

    As you can see the mass is bigger on the right side. Thats why it'll rotate to the right. But how do I calculate the mass difference?!


    Live for nothing, OR CODE FOR SOMETHING!
    • Changed type Dudeson Monday, May 10, 2010 3:52 PM
    Monday, May 10, 2010 3:50 PM

All replies

  • Try calculating the center of mass. This you can do by adding displacement (from say the point touching the ground) times mass for each point in both X and Y directions. Whatever you get, divide it by total mass to get the X and Y distance of center of mass.

    Mathematically

    X at Center of Mass = Summation((X value of each particle - X value of vertex) * Weight of that particle) / Total Weight

    similarly for Y and if needed for Z.

    If the X value of center of mass is +ve rotate right, else left.

    Tuesday, May 11, 2010 11:45 AM
  • Try calculating the center of mass. This you can do by adding displacement (from say the point touching the ground) times mass for each point in both X and Y directions. Whatever you get, divide it by total mass to get the X and Y distance of center of mass.

    I already calculated the center of mass. It's the big red dot. Or am i getting something wrong?

    X at Center of Mass = Summation((X value of each particle - X value of vertex) * Weight of that particle) / Total Weight

    "X at Center of Mass" what do you mean by that? The X position of the center of the mass? (the big red dot)

    And by "Weight of that particle", do you mean by that the shape doesn't have the same mass all over it? Like it's thicker on some places?

    Sorry.. I just don't get what you exactly mean.. heh.. But thx for the help!

     

     


    Live for nothing, OR CODE FOR SOMETHING!
    Tuesday, May 11, 2010 5:22 PM
  • Check out this for CG calculation http://home.earthlink.net/~robotb9/id14.html
    Tuesday, May 11, 2010 7:32 PM
  • The Center of Gravity of a rigid body must lie between the supports for the object if it needs to be stable. In the case of single support, the rotation about the "pivot" (the single support) is in the direction perpendicular to the line joining the the pivot with the center of mass. I am assuming here that the collision is between a rigid body and a flat surface.

    You may need to read up on rotational dynamics before you proceed further. Hyperphysics is a good reference to start.

    The rotation is defined by angular acceleration due to gravitational torque about the pivot. The force that gravity applies is F=m*g at the center of mass. You can calculate the Torque and Moment of Inertia to estimate the angular acceleration, or how the body's rotation about the pivoting axis speeds up.

    The body rotates till a second part of the body hits the surface. At this point elasticity and laws of collisions take over.

    In brief, this is what you may need to do:

    1. Calculate the force (F=m*g) at center of mass.

    2. Calculate the Torque = F x r about the pivot. (Refer to Hyperphysics link above)

    3. Calculate moment of inertia (I) of the body about the pivot.

    4. Calculate angular acceleration using Torque and Moment of Inertia above.

    5. Calculate angular velocity (degrees per second) using the following: New Angular Velocity = Old Angular Velocity + Angular Acceleration * Simulation Timestep. For simplicity, you may assume that when the body collides the Angular Velocity is 0 though this is not strictly true.

    6. Calculate the angle of the body using: New Angle = Old Angle + Angular Velocity * Simulation Timestep.

    I hope this helps.

     

    Wednesday, May 12, 2010 6:13 AM
  • Okay.

    Here's the new version, finally..  BXN264

     

    HOW TO USE: See instructions in the upper left corner of the window.

     

    How do I get it to stop rotating, guys?!


    Live for nothing, OR CODE FOR SOMETHING!
    • Edited by Dudeson Saturday, May 22, 2010 6:56 PM
    Friday, May 21, 2010 7:58 PM
  • Dudeson,

    This is a sweet physics demo.  I had a similar problem to you with a program I had, I made a bouncing ball that with every bounce would lose some energy with a multiplicative elasticity term, but it would still never quite stop bouncing.  If only I could duplicate this version of a perpetual motion machine in real life.  So although you'd expect that Object_Rotation would eventually hit zero due to the friction term, I think roundoff error is preventing it.  I would just put in an if-then statement to force Object_Rotation to 0 whenever it hits an arbitrarily small number. A more elegant solution might be to bump up the friction term a bit every time your object shifts axis of rotation.

    Neither method is strictly keeping with the laws of physics, obviously, and not very satisfying, but your example brings up an interesting instance of a 'fudge' that a programmer has to make sometimes to get a simulation to behave properly.

    ZP

    Friday, May 21, 2010 9:11 PM
  • I already thought about something like that...

    Here it is: QGP302

     

    It's not really satisfying if you ask me...

    You can check out the "Object_Checkwalls" Sub to take a look at what i did.


    Live for nothing, OR CODE FOR SOMETHING!
    Saturday, May 22, 2010 7:45 PM
  • Dudeson,

    I think you did it the proper way -- whenever two objects collide, kinetic energy is lost in the form of heat and noise.  Your technique of using the point in time when two corners in time are touching the ground to reduce rotation approximates that situation.  If you want to be a purist, you could introduce an elasticity term that reduces energy of the system at the point of impact of each corner with the ground, but I think the results would be nearly identical.

    By the way, check out this:

    number = 100

    friction = 0.98

    While

     

    number = number * friction

    TextWindow.WriteLine("Number = " + number)

    EndWhile

    Number never gets to zero...

    Cheers

    Z_P

    number > 0
    Saturday, May 22, 2010 11:53 PM