用坐标系求三角形的内角
Finding Triangle's inner angle with coordinate system
我正在编写一个代码,使用三角比告诉你三角形的内角。
这是我试过的。但是错误消息说:
这是代码和图片
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)
你需要这个:
cosC = ((lineA * lineA) + (lineB * lineB) - (lineC * lineC)) / (2 * lineA * lineB)
我正在编写一个代码,使用三角比告诉你三角形的内角。
这是我试过的。但是错误消息说:
这是代码和图片
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)
你需要这个:
cosC = ((lineA * lineA) + (lineB * lineB) - (lineC * lineC)) / (2 * lineA * lineB)