Projetile Motion problem

Started by
2 comments, last by chwpornstr 19 years, 4 months ago
Hi all, I am currently tryin to program a basketball game with a ball displaying the correct projectile motion. I searched all the threads AND my physics book, and they both display equations finding x and y positions,i.e. in 2D. But I am working in a 3D environment, meaning there is a Z position in account. How do I calculate the xyz positions? Thanks! I am using these equations to find X and Y: X = (v0cos(angle))t Y = (v0sin(angle))t - (1/2gt^2)
Advertisement
Using the formula in your book, x is the horizontal direction and y is vertical, with gravity acting in the negative y direction.

For 3D, x and z are 2 horizontal directions. So...it turns out to be really, really simple to convert your equations over to 3D. You need another angle. Lets look at a top-down view of your situation, in 3D:

           ^          Z|  /           | /           |/B           -------->X


Lets say that horizontally, the basketball moves approximately along that diagonal line, which makes angle B between the X and Z axes, horizontally. The angle B is measured in radian from X. As shown, its value is positive and its in the first quadrant.

To modify your equations, just include separate equations for X and Z, and leave the Y equation as is, with no change:

X = v0*cos(B)*cos(angle)*t
Z = v0*sin(B)*cos(angle)*t
Y = v0*sin(angle)*t - (1/2gt2)

All I've really done is convert your one horizontal direction X into a horizontal vector (X,Z).
Graham Rhodes Moderator, Math & Physics forum @ gamedev.net
That works, but depending on what GUI you are using, Z is the upwards component. Don't most GUIs go with the RHS?
Hi, Thanks for the equations!
But I think I'm calculating angle B wrong. How I'm doing it is that I'm taking the difference between the ball's initial position and the position of the hoop(where I want it to go) to get the distance of ball's X and Z displacement. Then I just arctan(Zdisplacement/Xdisplacement) to get the angle B. I don't believe that is precise. Any help? Thanks!!

This topic is closed to new replies.

Advertisement