Here is what I created below.
There has to be a more efficient way for my daughter who is a
beginning coder to implement this. What is the most efficient
methodology for coding this ? I especially would like to see a better
way to code what I call caseVII (negative angles less than -360)
HELP???
PYTHON CODE FOR FINDING A REFERENCE ANGLE IN DEGREES by Lee S.
import math
angle = float (input("Enter angle(deg) to calculate reference angle for : "))
#CASE 1 (<90 and > 0)
def caseI(angle):
angle=angle
print("Reference Angle = ",angle)
return (angle)
def caseII(angle):
#CASE II (>90 and <=180 )
angle=180.00-angle
print("Reference Angle = ",angle)
return (angle)
def caseIII(angle):
#CASEIII(>180 and <=270)
angle=angle-180.0
CASEIV(>270 and <360)
angle=360.00-angle
print("Reference Angle = ",angle)
return (angle)
def caseV(angle):
#CASEVI(>360 )
angle=(angle/360 - int (angle/360))*360
if angle >=0 and angle <= 90:
angle=angle
elif angle >90 and angle <=180:
angle=180.0-angle
elif angle >180 and angle <=270:
angle=angle-180.0
elif angle >270 and angle <=360:
angle=360.00-angle
print("Reference Angle = ",angle)
return (angle)
def caseVI(angle):
#CASE (<0 and <=-360)
angle = angle+360
if angle >=0 and angle <= 90:
angle=angle
elif angle >90 and angle <=180:
angle=180.0-angle
elif angle >180 and angle <=270:
angle=angle-180.0
elif angle >270 and angle <=360:
angle=360.00-angle
print("Reference Angle = ",angle)
return (angle)
def caseVII(angle):
#CASE7 (<-360 there has to be a more efficient way????)
angle=(angle/360 + abs(int (angle/360))*360)
angle = angle+360
if angle >=0 and angle <= 90:
angle=angle
elif angle >90 and angle <=180:
angle=180.0-angle
elif angle >180 and angle <=270:
angle=angle-180.0
elif angle >270 and angle <=360:
angle=360.00-angle
print("Reference Angle = ",angle)
return (angle)
if angle >=0 and angle <= 90:
caseI(angle)
elif angle >90 and angle <=180:
caseII(angle)
elif angle >180 and angle <=270:
caseIII(angle)
elif angle >270 and angle <=360:
caseIV(angle)
elif angle >360:
caseV(angle)
elif angle <0 and angle >=-360:
caseVI(angle)
else:
caseVII(angle)