Angle
기하학에서, 각(角 영어: angle)은 같은 끝점을 갖는 두 반직선이 이루는 도형이다. 이 끝점을 각의 꼭짓점(-點, 영어: vertex)이라고 하며, 두 반직선을 각의 변(邊, 영어: side)이라고 한다. 각의 두 변이 벌어진 정도, 즉 각의 크기를 나타내는 양을 각도(角度)라고 한다. 엄밀하게 말하면, 시초선에서 동경까지 시계 반대방향으로 벌어진 정도이다. 보통 각이라고 하면 평면상에서 정의되는 것을 말하지만 3차원 공간에서 말하는 입체각도 정의할 수 있다.
두 선으로 각도 구하는 방법
이론
Find_the_Angle_between_three_points.png
Python
# -*- coding: utf-8 -*-
import math
from typing import NamedTuple
class Point(NamedTuple):
x: int
y: int
def angle(a: Point, b: Point, c: Point) -> float:
ang = math.degrees(math.atan2(c[1]-b[1], c[0]-b[0]) - math.atan2(a[1]-b[1], a[0]-b[0]))
return ang + 360 if ang < 0 else ang
Using Numpy Library
import numpy as np
a = np.array([6,0])
b = np.array([0,0])
c = np.array([0,6])
ba = a - b
bc = c - b
cosine_angle = np.dot(ba, bc) / (np.linalg.norm(ba) * np.linalg.norm(bc))
angle = np.arccos(cosine_angle)
print np.degrees(angle)