题解 | #正三角形的顶点位置#
正三角形的顶点位置
https://www.nowcoder.com/practice/d10dc47192234e0f81f5056e5ce7dd35
import math
T = int(input())
for _ in range(T):
x1, y1, x2, y2 = map(float, input().split())
n_x = x2 - x1
n_y = y2 - y1
cos_60 = math.cos(math.pi / 3)
sin_60 = math.sin(math.pi / 3)
# 计算旋转后的坐标
t1_x = cos_60 * n_x - sin_60 * n_y
t1_y = sin_60 * n_x + cos_60 * n_y
t2_x = cos_60 * n_x + sin_60 * n_y
t2_y = -sin_60 * n_x + cos_60 * n_y
# 计算两个旋转后的点的坐标
x3 = t1_x + x1
y3 = t1_y + y1
x4 = t2_x + x1
y4 = t2_y + y1
# 输出结果,保留两位小数
points = [(x3, y3), (x4, y4)]
points.sort() # 按照 x 坐标排序
print("{:.2f} {:.2f} {:.2f} {:.2f}".format(points[0][0], points[0][1], points[1][0], points[1][1]))

查看12道真题和解析