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.
2 Réponses
+ 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.
0
Thank you very much <3