0

Program with point and a ball.

Please can you help me with program which has to check if point is inside the ball, on the ball or outside the ball. User must cin>> x,y,z of the point and x,y,z of the ball.

23rd Oct 2017, 12:56 PM
szymonides98
2 Respostas
+ 2
You need another variable 'r'(radius) for the sphere/ball. Then you can form the equation : x^2 + y^2 + z^2 = r^2. Then just plug the values for x y and z from the point, and check if the the result is : >r^2 = Outside. =r^2 = On the sphere. <r^2 = Inside. I assume, all your spheres start from origin. If not, you will need another point (the new origin or center) (lets say a,b,c) and the new equation would become: (x-a)^2 + (y-b)^2 + (z-c)^2 = r^2.
23rd Oct 2017, 2:15 PM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
0
Thank you very much <3
23rd Oct 2017, 2:21 PM
szymonides98