Results 1 to 10 of 10

Thread: gravity

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    ok I have my gravity equation, how would I go about putting this into speeds? (x and y speeds)...? Maybe the next step would be A = F/M?

  2. #2
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    'speed' is a scalar quantity (it is just a magnitude), what you are talking about is 'velocity', which is a vector quantity because it has both a magnitude and a direction. It's a minor technical point

    Yes, I would suggest you go ahead with a = f/m.
    Harry.

    "From one thing, know ten thousand things."

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    ok im doing good, but I'm having trouble using the gravity constant, it's so small....that the computer reads it as 0...

    const double grav = (6.7*pow(10,-11));

    comes up as 0 when I test it in a messagebox

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    ok can someone check my math? here's my algorithm:

    Code:
    //get x force
    						//get radius
    						xradius = body1.x-body2.x;
    					
    					xforce = grav*((body1.mass * body2.mass) / (xradius));
    					xaccel = (xforce / body2.mass);
    					body2.xspeed = body2.xspeed + xaccel;
    
    					body2.x = body2.x + body2.xspeed;
    
    					//get y force
    						//get radius
    						yradius = body1.y-body2.y;
    					
    					yforce = (grav * body1.mass * body2.mass) / (yradius);
    					yaccel = (yforce / body2.mass);
    					body2.yspeed = body2.yspeed + yaccel;
    
    					body2.y = body2.y + body2.yspeed;
    					
    
    
    					SetMoons();
    SetMoons() just draws the moons from the information in each class....

    basically I get the force from the equation

    F = constant * ((m1*m2)/radius2);
    and then put that into A = MF

    Accel = body1.mass * force;

    and then added accel to the speed....I did this for X and Y....but it doesn't work right

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    anyone?

    its not working....the "moon" goes all over the place...

  6. #6
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    I think your Force formula should be like this:
    F = (constant * m1*m2)/radius2;

    and you're also not squaring your radius in your code so it should be like:
    xforce = (grav* body1.mass * body2.mass) / xradius2;
    yforce = (grav * body1.mass * body2.mass) / yradius2;
    Baaaaaaaaah

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800

    Thumbs up

    Attached Files Attached Files

  8. #8
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827

    Thumbs up

    Good job! It looks really amazing!
    BTW, I think there's a bug when closing the window. Perhaps you can stop your loop or timer for drawing when a WM_CLOSE or WM_DESTORY message is sent to your window?
    Baaaaaaaaah

  9. #9

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    Yeah sorry, while the animation (for loop) is going to make it able to be seen I put some sleep statements in there. Im not too good with animation.

    BTW Without the sleep statement it looks really cool..I thnk I added that one into the zip too

  10. #10
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    You should create a background thread to do the drawing, else the app can only be closed with Ctrl+Alt+Del. Or use PeekMessage instead of GetMessage and use idle time for drawing.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width