# Projetile Motion problem

This topic is 4824 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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)

##### Share on other sites
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).

##### Share on other sites
That works, but depending on what GUI you are using, Z is the upwards component. Don't most GUIs go with the RHS?

##### Share on other sites
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!!