Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """ Calculate the angle between two lines that join at (x1, y1) """
- from math import atan2, pi
- def calculate_angle(x1,y1,x2,y2,x3,y3,x4,y4):
- # Calculate the angles created.
- delta_x = float(x2 - x1)
- delta_y = float(y2 - y1)
- answer = atan2(delta_y, delta_x)*180.0/pi
- delta_x = float(x4 - x3)
- delta_y = float(y4 - y3)
- answer1 = atan2(delta_y, delta_x)*180.0/pi
- # Get the answer
- if answer > answer1:
- return answer-answer1
- else:
- return answer1-answer
- # Input stuff
- print "Input coordinates for the first line"
- print "------------------------------------"
- x1 = float(raw_input('Enter x1 coord >'))
- y1 = float(raw_input('Enter y1 coord >'))
- x2 = float(raw_input('Enter x2 coord >'))
- y2 = float(raw_input('Enter y2 coord >'))
- print ""
- print "Input coordinates for the second line"
- print "Lets assume the node for the two lines is at (x1,y1)"
- print "------------------------------------"
- x3, y3 = x1 ,y1
- print "x3 =",x1
- print "y3 =",y1
- x4 = float(raw_input('Enter x4 coord >'))
- y4 = float(raw_input('Enter y4 coord >'))
- result = calculate_angle(x1,y1,x2,y2,x3,y3,x4,y4)
- print "The angle between the two joined lines is",result
Advertisement
Add Comment
Please, Sign In to add comment