-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharc.py
26 lines (20 loc) · 869 Bytes
/
arc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from math import pi
class ArcException(Exception):
pass
def arc_length(theta, radius=False, circumference=False):
# Either radius and circumference need to be passed in
if not radius and not circumference:
raise ArcException("No radius or circumference passed in.")
# If both radius and circumference are passed in and don't match each
# other, then raise an error
if (radius and circumference) and (radius != circumference / 2):
raise ArcException("Both radius and circumference are passed in \
and do not match each other.")
# Calculate radius based on circumference if no radius provided
if not radius:
radius = circumference / 2
# Convert to floats
theta = float(theta) # degree of arc
radius = float(radius) # radius of circle
# Do the math
return (theta / 360) * (2 * pi * radius)