chwpornstr 122 Report post Posted December 4, 2004 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) 0 Share this post Link to post Share on other sites
grhodes_at_work 1385 Report post Posted December 4, 2004 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 -------->XLets 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)*tZ = v0*sin(B)*cos(angle)*tY = v0*sin(angle)*t - (1/2gt^{2})All I've really done is convert your one horizontal direction X into a horizontal vector (X,Z). 0 Share this post Link to post Share on other sites
ParanoiaComplex 122 Report post Posted December 4, 2004 That works, but depending on what GUI you are using, Z is the upwards component. Don't most GUIs go with the RHS? 0 Share this post Link to post Share on other sites
chwpornstr 122 Report post Posted December 5, 2004 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!! 0 Share this post Link to post Share on other sites