题解 | #正三角形的顶点位置#

正三角形的顶点位置

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]))

全部评论

相关推荐

04-02 16:49
门头沟学院 Java
_bloodstream_:我也面了科大讯飞,主管面的时候听说急招人优先考虑能尽快实习的,我说忙毕设,后面就一直没消息了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务