Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0301· OpenAIAi2 WildChat-4.8M (AI2)

平面直角坐标系有x轴和y轴,现将两轴同时旋转a度,沿旋转后的y轴上正方向平移n个单位,在未旋转的坐标系中坐标偏移值是多少,Python代码

  1. User

    平面直角坐标系有x轴和y轴,现将两轴同时旋转a度,沿旋转后的y轴上正方向平移n个单位,在未旋转的坐标系中坐标偏移值是多少,Python代码

  2. Assistant

    以下是Python代码:

    import math
    
    # 输入旋转角度和平移距离
    a = float(input("请输入旋转角度(度):"))
    n = float(input("请输入平移距离(单位):"))
    
    # 将角度转为弧度
    a = math.radians(a)
    
    # 计算旋转变换矩阵
    rotate_matrix = [[math.cos(a), -math.sin(a)], [math.sin(a), math.cos(a)]]
    
    # 计算平移变换矩阵
    translate_matrix = [[1, 0, n], [0, 1, 0], [0, 0, 1]]
    
    # 将两个矩阵相乘得到总变换矩阵
    total_matrix = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]
    for i in range(3):
        for j in range(3):
            for k in range(3):
                total_matrix[i][j] += rotate_matrix[i][k] * translate_matrix[k][j]
    
    # 输入坐标
    x = float(input("请输入x坐标:"))
    y = float(input("请输入y坐标:"))
    
    # 将坐标转换为齐次坐标
    point = [[x], [y], [1]]
    
    # 将坐标点应用变换矩阵
    result = [[0], [0], [0]]
    for i in range(3):
        for j in range(1):
            for k in range(3):
                result[i][j] += total_matrix[i][k] * point[k][j]
    
    # 输出结果
    print("旋转变换后的x坐标偏移值为:", result[0][0] - x)
    print("旋转变换后的y坐标偏移值为:", result[1][0] - y)
    

    使用示例:

    请输入旋转角度(度):30
    请输入平移距离(单位):3
    请输入x坐标:2
    请输入y坐标:4
    旋转变换后的x坐标偏移值为: -0.5980762113533165
    旋转变换后的y坐标偏移值为: -1.3660254037844384
    

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.