def add_angles_ba(angle1, angle2): # Initialize sum sum = classes.Angle("Sum", 0, 0, 0) angle1.degrees += 180 # Same deal... # If sum of seconds is greater than 60, add 1 minute and subtract 60 seconds if angle1.seconds + angle2.seconds > 60: sum.minutes = 1 sum.seconds = angle1.seconds + angle2.seconds - 60 else: sum.seconds += angle1.seconds + angle2.seconds # If sum of minutes is greater than 60, add 1 degree and subtract 60 minutes if angle1.minutes + angle2.minutes > 60: sum.degrees = 1 sum.minutes += angle1.minutes + angle2.minutes - 60 else: sum.minutes += angle1.minutes + angle2.minutes # If sum is greater than 360 degrees, subtract 360 if angle1.degrees + angle2.degrees + sum.degrees > 360: sum.degrees += angle1.degrees + angle2.degrees - 360 else: sum.degrees += angle1.degrees + angle2.degrees # If sum is yet still greater than 360 degrees, subtract 360 if sum.degrees > 360: sum.degrees -= 360 return sum
def subtract_angles_ba(angle1, angle2): # Initialize difference difference = classes.Angle("Difference", 0, 0, 0) angle1.degrees -= 180 #... # If difference of seconds is less than 0, subtract 1 minute and add 60 seconds if (angle1.seconds - angle2.seconds) < 0: difference.minutes = -1 difference.seconds = (60 + angle1.seconds - angle2.seconds) else: difference.seconds = (angle1.seconds - angle2.seconds) # If difference of minutes is less than 0, subtract 1 degree and add 60 minutes if (angle1.minutes - angle2.minutes + difference.minutes) < 0: difference.degrees = -1 difference.minutes += (60 + angle1.minutes - angle2.minutes) else: difference.minutes += (angle1.minutes - angle2.minutes) # If difference is less than 0 degrees, add 360 if (angle1.degrees - angle2.degrees + difference.degrees) < 0: difference.degrees += (360 + angle1.degrees - angle2.degrees) else: difference.degrees += (angle1.degrees - angle2.degrees) return difference
def add_angles_raw(angle1, angle2): # Initialize sum sum = classes.Angle("Sum", 0, 0, 0) # If sum of seconds is greater than 60, add 1 minute and subtract 60 seconds if angle1.seconds + angle2.seconds >= 60: sum.minutes = 1 sum.seconds = angle1.seconds + angle2.seconds - 60 else: sum.seconds += angle1.seconds + angle2.seconds # If sum of minutes is greater than 60, add 1 degree and subtract 60 minutes if angle1.minutes + angle2.minutes + sum.minutes >= 60: sum.degrees = 1 sum.minutes += angle1.minutes + angle2.minutes - 60 else: sum.minutes += angle1.minutes + angle2.minutes sum.degrees += angle1.degrees + angle2.degrees return sum
# I am giving Todd Horton's loop azimuth video a spin. He is a great educator! # https://www.youtube.com/watch?v=x3cAL1raSDY&t=842s # I will write an interface for this eventually, when I need it for class. # Written by Ryan Prasad. Contact: [email protected] import classes import functions angle_cd = classes.Angle("CD", 205, 27, 53) angle_d = classes.Angle("D", 112, 54, 17) angle_e = classes.Angle("E", 105, 41, 56) angle_a = classes.Angle("A", 72, 32, 2) angle_b = classes.Angle("B", 142, 26, 5) angle_c = classes.Angle("C", 106, 25, 40) print("Solved clockwise:") print("CD") print(angle_cd.degrees, angle_cd.minutes, angle_cd.seconds) angle_de = functions.subtract_angles_ba(angle_cd, angle_d) print("DE") print(angle_de.degrees, angle_de.minutes, angle_de.seconds) angle_ea = functions.subtract_angles_ba(angle_de, angle_e) print("EA") print(angle_ea.degrees, angle_ea.minutes, angle_ea.seconds) angle_ab = functions.subtract_angles_ba(angle_ea, angle_a) print("AB") print(angle_ab.degrees, angle_ab.minutes, angle_ab.seconds)
# My Python solution to Todd Horton's Traverse angle adjustment video # https://www.youtube.com/watch?v=3JoIkovf0e0&t=241s # Written by Ryan Prasad on a rainy 5/5/19. Email: [email protected] import classes import functions # Exercise angles hard coded: angle_ab = classes.Angle("AB", 94, 16, 27) angle_a = classes.Angle("A", 89, 35, 50) angle_b = classes.Angle("B", 56, 51, 51) angle_c = classes.Angle("C", 233, 38, 51) angle_d = classes.Angle("D", 64, 57, 52) angle_e = classes.Angle("E", 94, 55, 15) # Create a list containing interior angles interior_angles = [angle_a, angle_b, angle_c, angle_d, angle_e] # Initialize an angle at 0 for the following operation sum_interior = classes.Angle("ZZZ", 0, 0, 0) # Sum the interior angles for angle in interior_angles: sum_interior = functions.add_angles_raw(sum_interior, angle) print("Sum of interior angles:") print(sum_interior.degrees, sum_interior.minutes, sum_interior.seconds) print() # Calculate the sum of angles of a perfect polygon
# Don't try to break me! I am merely written to save time on survey exams. # Written by Ryan Prasad. Contact: [email protected] import classes import functions # Prompt user for two angles print("Subtract angles") angle1 = classes.Angle(input("Enter angle #1 name: "), int(input("Enter angle #1 degrees: ")), int(input("Enter angle #1 minutes: ")), int(input("Enter angle #1 seconds: "))) angle2 = classes.Angle(input("Enter angle #2 name: "), int(input("Enter angle #2 degrees: ")), int(input("Enter angle #2 minutes: ")), int(input("Enter angle #2 seconds: "))) # Subtract the angles difference = functions.subtract_angles(angle1, angle2) # Print output to console print(angle1.name + " -", angle2.name + " =") print(difference.degrees, difference.minutes, difference.seconds)