NumPy,Python中的矩阵乘以球形参数方程式

问题描述 投票:0回答:1

我以这种方式定义了一个球体:

sigma, theta = np.mgrid[0:2*np.pi:60j, 0:np.pi:30j]
x = np.cos(sigma) * np.sin(theta)
y = np.sin(sigma) * np.sin(theta)
z = np.cos(theta)

我正在按如下方式绘制所述球体:

fig = plt.figure()
ax = plt.axes(projection='3d')
ax.plot_surface(x, y, z, label='Unit sphere')
plt.show()

这按预期工作。但是,我需要通过将其参数方程式乘以3x3矩阵将其转换为椭球体,如下所示:

A1 = np.random.uniform(-1,1,(3,3))

现在,从数学的角度来看,我完全意识到我正在寻找的是我的x,y和z方程的垂直向量,并与我的3x3转换矩阵乘以矩阵乘法(@)。但是,我不知道如何在numpy中进行编码。预先感谢。

python numpy matrix vector matrix-multiplication
1个回答
0
投票

您可以使用理解循环将变换矩阵与每组x,y,z相乘

原始

enter image description here

ellipsoid = np.array([np.column_stack((x[i],y[i],z[i])) @ A1 for i in range(60)])
x_ellipsoid  = ellipsoid [:,:,0]
y_ellipsoid  = ellipsoid [:,:,1]
z_ellipsoid  = ellipsoid [:,:,2]

fig = plt.figure()
ax = plt.axes(projection='3d')
ax.plot_surface(x_ellipsoid, y_ellipsoid, z_ellipsoid, label='ellipsoid ')
plt.show()

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.