Constant
Constant

Reputation: 29

Finding Triangle's inner angle with coordinate system

I'm making a code which tells you the inner angle of the triangle by using Trigonometric ratio.

This is what I tried. But the error message says:

enter image description here

This is the code and the picture

import math

print("A(a,b) / B(c,d) / C(e,f) 세 점의 좌표 입력")
print("편의를 위해 각 대변을 A^ / B^ / C^ 라고 하겠습니다")

x= input("input a")
a= int(x)

x= input("input b")
b= int(x)

x= input("input c")
c= int(x)

x= input("input d")
d= int(x)

x= input("input e")
e= int(x)

x= input("input f")
f= int(x)

class Point2D:
    def __init__(self, x, y):
        self.x = x
        self.y = y
 
p1 = Point2D(x=a, y=b)
p2 = Point2D(x=c, y=d)
 
linea = p2.x - p1.x
lineb = p2.y - p1.y
 
lineC = math.sqrt((linea * linea) + (lineb * lineb))  
print("C^ =",lineC) 



p1 = Point2D(x=c, y=d) 
p2 = Point2D(x=e, y=f) 
 
linea = p2.x - p1.x  
lineb = p2.y - p1.y 
 
lineA = math.sqrt((linea * linea) + (lineb * lineb))  
print("A^ =",lineA) 



p1 = Point2D(x=a, y=b)  
p2 = Point2D(x=e, y=f) 
 
linea = p2.x - p1.x  
lineb = p2.y - p1.y  
 
lineB = math.sqrt((linea * linea) + (lineb * lineb)) 
print("B^ =",lineB)

cosC = ((lineA * lineA) + (lineB * lineB) - (lineC * lineC)) / 2 * lineA * lineB
math.acos(cosC)

enter image description here

Upvotes: 0

Views: 50

Answers (1)

expl25
expl25

Reputation: 36

You need this:

cosC = ((lineA * lineA) + (lineB * lineB) - (lineC * lineC)) / (2 * lineA * lineB)

Upvotes: 1

Related Questions