You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Python中构造指定的三种三维变换矩阵?

构造指定3×3变换矩阵的代码实现

绕Y轴旋转135度的矩阵Ry

绕Y轴的右手系旋转矩阵公式为:

Ry(θ) = [
[cosθ, 0, sinθ],
[0, 1, 0],
[-sinθ, 0, cosθ]
]

需先将角度转换为弧度(三角函数库默认以弧度为单位计算),再代入生成矩阵:

import math

degreey = 135
theta_y = math.radians(degreey)
Ry = [
    [math.cos(theta_y), 0, math.sin(theta_y)],
    [0, 1, 0],
    [-math.sin(theta_y), 0, math.cos(theta_y)]
]

绕Z轴旋转60度的矩阵Rz

绕Z轴的右手系旋转矩阵公式为:

Rz(θ) = [
[cosθ, -sinθ, 0],
[sinθ, cosθ, 0],
[0, 0, 1]
]

同样转换弧度后计算:

degreez = 60
theta_z = math.radians(degreez)
Rz = [
    [math.cos(theta_z), -math.sin(theta_z), 0],
    [math.sin(theta_z), math.cos(theta_z), 0],
    [0, 0, 1]
]

参数sh=1.0的剪切矩阵SH

要求将y分量添加到x分量,对应变换规则为 x' = x + sh*y、y' = y、z' = z,生成的剪切矩阵如下:

sh = 1.0
SH = [
    [1, sh, 0],
    [0, 1, 0],
    [0, 0, 1]
]

如果需要用numpy进行后续矩阵运算,可将列表转换为numpy数组:

import numpy as np

Ry_np = np.array(Ry)
Rz_np = np.array(Rz)
SH_np = np.array(SH)

内容的提问来源于stack exchange,提问作者BornTie

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.17 15:20:32