Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SciProg2024
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pclark3
SciProg2024
Commits
a231348c
Commit
a231348c
authored
1 year ago
by
cprutean
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
c07be827
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
CodeExamples/InsideSphere.ipynb
+72
-0
72 additions, 0 deletions
CodeExamples/InsideSphere.ipynb
with
72 additions
and
0 deletions
CodeExamples/InsideSphere.ipynb
0 → 100644
+
72
−
0
View file @
a231348c
{
"cells": [
{
"cell_type": "markdown",
"id": "3afb0d80",
"metadata": {},
"source": [
"# Inside Sphere"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d7072d10",
"metadata": {},
"outputs": [],
"source": [
"\"\"\" \n",
" Demonstrate a logical function to test if a point is inside or\n",
" outside of a sphere of give radius.\n",
"\"\"\"\n",
"\n",
"import math\n",
"\n",
"def inside(radius, x, y, z):\n",
" \"\"\"\n",
" Check if point x,y,x is inside a sphere of radius r\n",
" \"\"\"\n",
" lenSqr = x*x + y*y + z*z # length squared; this avoids sqrt() for efficiency.\n",
" if lenSqr <= radius*radius : # Is inside sphere\n",
" return True # Return logical True\n",
" else: # Else outside\n",
" return False # Return logical False\n",
"\n",
"\n",
"def main():\n",
" radius = 5.0\n",
" x = float(input(\"X value : \"))\n",
" y = float(input(\"Y value : \"))\n",
" z = float(input(\"Z value : \"))\n",
"\n",
" if inside(radius,x,y,z): # Use the function above to do the work\n",
" print(\"Point is inside sphere of radius : \" + str(radius))\n",
" else:\n",
" print(\"Point is outside sphere of radius : \" + str(radius))\n",
"\n",
"main()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
%% 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
()
```
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment