Thread: Physics: Kind of like a cannonball...

  1. #1
    Ecologist
    Join Date
    Aug 2001
    Location
    Utah.
    Posts
    1,291

    Physics: Kind of like a cannonball...

    Eek. It's been about 2 years since I've been in a
    physics class, and since my memory is terrible
    (it's because of the video games, according to
    Japan's Tohoku University
    ), I can't remember
    much of it.


    I'm trying to find a tutorial that explains the
    physics of something launching upwards at a
    certain angle/speed, then falling. An example
    of the movement I'm talking about, would be kind
    of like a flying cannonball. Am I making sense?

    Will someone explain the physics of this to me,
    or point me to a tutorial that does?
    Staying away from General.

  2. #2
    Registered User Gwargh's Avatar
    Join Date
    Aug 2001
    Posts
    7
    Let's see how much I remember from physics...

    Well, an object's horizontal movement is independent of its vertical movement, so if you throw a ball, it will keep moving horizontally at a constant speed (ignoring friction/air resistance, which you might have to incorporate into your physics logic) even though gravity causes it to accelerate downward at 9.8 m/s/s.

    I would recommend doing the calculations before launching the cannon, because it's all based on the angle. Find out how many units horizontally and how many units vertically the cannonball will move at a time based on the angle. Unless you decide to implement friction/air resistance (which I'm a little rusty on, ask someone else about that), the variable for horizontal speed will not change throughout the flight, but the variable for vertical speed must be decreased by 9.8 m/s/s (or some reasonable equivalent ) with each loop of your logic.

  3. #3
    Scourfish
    Guest
    As I recall, the velocity of an object on the horizontal is cos(d/t), accelleration being cos(d/t^2), and sin(d/t) or sin(d/t^2) for the vertical. Of course, this is simple stuff that you probably already knew; if so, ignore me talking out of my butt.

  4. #4
    Registered User Esss's Avatar
    Join Date
    Aug 2001
    Posts
    133
    Start with a velocity u and an angle a, at (0, 0).

    Horizontal velocity uH = u cos a
    Vertical velocity uV = u sin a

    Then, at time t:

    Horizontal position x = uH t
    Vertical position y = uV t - 1/2 g(t^2)

    I feel a Gorilla (remember?) game coming on...
    Ess
    Like a rat in a maze who says,
    "Watch me choose my own direction"
    Are you under the illusion
    The path is winding your way?
    - Rush

  5. #5
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    That gorilla game was cool... but tank wars was the greatest .
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

  6. #6
    Registered User Aran's Avatar
    Join Date
    Aug 2001
    Posts
    1,301
    Does anyone still play Blast Doors? what an insane and fun game!

  7. #7
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Try this. It seems to go into quite a lot of detail. I am actually reading it right now!
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  8. #8
    Registered User
    Join Date
    Sep 2001
    Posts
    48
    gorilla, now that was a game.
    astride a storied past, thats everywhere you are

  9. #9
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Hey Static, did you check out that URL? I read it last night and it seems to answer your question quite well!
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  10. #10
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Also if you would like some help working it into some code, I would be willing to help...
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  11. #11
    Ecologist
    Join Date
    Aug 2001
    Location
    Utah.
    Posts
    1,291
    Hey, yeah, thanks. I printed it out... Haven't
    read it yet... I'll read it tonight.
    Staying away from General.

  12. #12
    Unregistered
    Guest
    Here's an algorithim that might work:

    grav = the pull of gravity each time interval
    move_u = verticle speed
    move_f = horivontal speed
    at_z = current height
    at_x = current x (horivontal) position
    start_z
    Start_x
    array_z
    array_x

    while !(( start_z == at_z ) && ( move_u <= 0 ))
    {
    array_z = at_z;
    array_x = at_x;
    move_u -= grav;
    at_z += move_u;
    at_x += move_f;
    }

    you might need trig to get move_z and move_x, but maybe not. Depends on your code.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What kind of job...
    By Discolemonade in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 08-15-2005, 08:23 PM
  2. physics
    By psychopath in forum Game Programming
    Replies: 5
    Last Post: 05-09-2005, 04:38 PM
  3. what physics courses
    By EvBladeRunnervE in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 10-22-2003, 12:19 PM
  4. AP Physics B
    By confuted in forum A Brief History of Cprogramming.com
    Replies: 22
    Last Post: 05-04-2003, 12:33 PM
  5. February 1, 2019...
    By Cheeze-It in forum A Brief History of Cprogramming.com
    Replies: 98
    Last Post: 08-03-2002, 07:24 AM