Skip to content

Instantly share code, notes, and snippets.

@Nate-Wessel
Created March 9, 2018 18:29
Show Gist options
  • Save Nate-Wessel/e0a549d75336659aafc3b33e53297570 to your computer and use it in GitHub Desktop.
Save Nate-Wessel/e0a549d75336659aafc3b33e53297570 to your computer and use it in GitHub Desktop.
Python function for calculating a planar inner angle of three points
def inner_angle_plane(point1,point2,point3):
"""Given three points, p1
calculate the smaller of the two angles \ a
formed by the sequence. \
Returns degrees. p2------p3
Input is three (x,y) tuples
"""
# be sure there IS an angle to measure
assert point1 != point2 and point2 != point3
# get coordinate values
p1x,p1y = point1
p2x,p2y = point2
p3x,p3y = point3
# the rounding is for rare precision issues with acos() at ~ 180 degrees
radians = math.acos( round(
(
( (p2x-p1x)**2 + (p2y-p1y)**2 ) +
( (p2x-p3x)**2 + (p2y-p3y)**2 ) -
( (p3x-p1x)**2 + (p3y-p1y)**2 )
) /
math.sqrt(
4 *
( (p2x-p1x)**2 + (p2y-p1y)**2 ) *
( (p2x-p3x)**2 + (p2y-p3y)**2 )
)
, 10 ) )
degrees = math.degrees(radians)
assert degrees <= 180
return degrees
@Nate-Wessel
Copy link
Author

Well, my image works with 3-space tabs but not here :-/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment