Skip to content
Snippets Groups Projects
Commit a231348c authored by cprutean's avatar cprutean
Browse files

Upload New File

parent c07be827
No related branches found
No related tags found
No related merge requests found
%% Cell type:markdown id:3afb0d80 tags:
# Inside Sphere
%% Cell type:code id:d7072d10 tags:
``` python
"""
Demonstrate a logical function to test if a point is inside or
outside of a sphere of give radius.
"""
import math
def inside(radius, x, y, z):
"""
Check if point x,y,x is inside a sphere of radius r
"""
lenSqr = x*x + y*y + z*z # length squared; this avoids sqrt() for efficiency.
if lenSqr <= radius*radius : # Is inside sphere
return True # Return logical True
else: # Else outside
return False # Return logical False
def main():
radius = 5.0
x = float(input("X value : "))
y = float(input("Y value : "))
z = float(input("Z value : "))
if inside(radius,x,y,z): # Use the function above to do the work
print("Point is inside sphere of radius : " + str(radius))
else:
print("Point is outside sphere of radius : " + str(radius))
main()
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment