You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
WRC/curvature.py

49 lines
1.2 KiB
Python

1 year ago
import math
A = [100.012, -9.789]
C = [100.076, -10.083]
B = [100.043, -9.937]
s = abs((A[0] * B[1] + B[0] * C[1] + C[0] * A[1] - A[1] * B[0] - B[1] * C[0] - C[1] * 1) / 2)
print('s',s)
a = abs(math.sqrt(abs(A[0] - C[0]) ** 2) + abs((A[1] - C[1]) ** 2))
print('a',a)
b = abs(math.sqrt(abs(B[0] - C[0]) ** 2) + abs((B[1] - C[1]) ** 2))
print('b',b)
c = abs(math.sqrt(a ** 2 + b ** 2))
print('c',c)
k = 4 * s / (a * b * c)
print(k)
# import numpy as np
# def get_arc_curve(pts):
# '''
# 获取弧度值
# :param pts:
# :return:
# '''
#
# # 计算弦长
# start = np.array(pts[0])
# end = np.array(pts[len(pts) - 1])
# l_arc = np.sqrt(np.sum(np.power(end - start, 2)))
#
# # 计算弧上的点到直线的最大距离
# # 计算公式:\frac{1}{2a}\sqrt{(a+b+c)(a+b-c)(a+c-b)(b+c-a)}
# a = l_arc
# b = np.sqrt(np.sum(np.power(pts - start, 2), axis=1))
# c = np.sqrt(np.sum(np.power(pts - end, 2), axis=1))
# dist = np.sqrt((a + b + c) * (a + b - c) * (a + c - b) * (b + c - a)) / (2 * a)
# h = dist.max()
#
# # 计算曲率
# r = ((a * a) / 4 + h * h) / (2 * h)
#
# return r
#
#
# if __name__ == '__main__':
# x = np.linspace(1, 100, 99).astype(np.int64)
# y = (x ** 2)
# xy = list(zip(x, y)) # list of points in 2D space
# print(get_arc_curve(xy))