在3D平面中给定x和z的y坐标

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

我已经生成了一个3D圆形平面,该平面已沿x轴旋转了45度:

enter image description here

考虑到x和z坐标,我想确定平面的y坐标,但是我不知道该怎么做。如何对平面进行插值,以便在将x坐标和z坐标馈入平面时可以得到y坐标?

这是我的代码:

def coord_rotation(theta):
    # Convert to radians
    theta_1_rad = theta[0] * np.pi/180.0
    theta_2_rad = theta[1] * np.pi/180.0
    theta_3_rad = theta[2] * np.pi/180.0
    # The bicone and dust angles correspond to Euler angles which are 
    # (e1,e2,e3) -> (rotation about z, rotation about x, rotation about z again)
    theta_1,theta_2,theta_3 = theta_1_rad,theta_2_rad,theta_3_rad
    R_x = np.array([[1,         0,                  0                   ],
                    [0,         np.cos(theta_1),   np.sin(theta_1)   ],
                    [0,         -np.sin(theta_1),  np.cos(theta_1)    ]
                    ])
    R_y = np.array([[np.cos(theta_2),    0,        -np.sin(theta_2)    ],
                    [0,                   1,        0                    ],
                    [np.sin(theta_2),    0,         np.cos(theta_2)    ]
                    ])
    R_z = np.array([[np.cos(theta_3),       np.sin(theta_3),        0],
                    [-np.sin(theta_3),      np.cos(theta_3),       0],
                    [0,                      0,                      1]
                    ])             
    R = np.dot(R_z, np.dot( R_y, R_x ))
    return R

theta_D1_deg  = -45.0)
theta_D3_deg  = 0.0  
D = 2
sampling = 25
########################################################################################
phi       = 2*np.pi # rotation 
phi    = np.linspace(0,phi,sampling)
r      = np.linspace(-D,D,sampling)

ri,pi = np.ix_(r,phi) # get open grids            
X = ri*np.cos(pi)
Y = ri*np.sin(pi)
Z = np.zeros(np.shape(X))
# Rotate the dust plane in 3d
t = np.transpose(np.array([X,Y,Z]), (1,2,0))
R = coord_rotation((theta_D1_deg,0,theta_D3_deg))
xd,yd,zd = np.transpose(np.dot(t, R), (2,0,1))

# Make uniform grid
points = (xd.ravel(),yd.ravel())
values = zd.ravel()
xdgrid,ydgrid = np.meshgrid(np.linspace(-2,2,1000),np.linspace(-2,2,1000))
zdgrid = griddata(points, values, (xdgrid, ydgrid), method='linear')

# Plot
fig = plt.figure(figsize=(6,6))
ax1 = fig.add_subplot(1,1,1, projection='3d')
ax1.view_init(elev=15, azim=35)
ax1.plot_wireframe(xdgrid,ydgrid,zdgrid,alpha=0.25,color='xkcd:orange',zorder=3)

fontsize = 12
# x-axis
ax1.set_xlim(-2,2)
ax1.set_xlabel(r'$x$',fontsize=fontsize)
xAxisLine = ((np.min(xd), np.max(xd)), (0, 0), (0,0))
ax1.plot(xAxisLine[0], xAxisLine[1], xAxisLine[2], color='black',zorder=1,alpha=0.5)
# y-axis
ax1.set_ylim(-2,2)
ax1.set_ylabel(r'$y$',fontsize=fontsize)
yAxisLine = ((0, 0), (np.min(yd), np.max(yd)), (0,0))
ax1.plot(yAxisLine[0], yAxisLine[1], yAxisLine[2], color='black',zorder=1,alpha=0.5)
# z-axis
ax1.set_zlim(-2,2)
ax1.set_zlabel(r'$z$',fontsize=fontsize)
zAxisLine = ((0, 0), (0,0), (np.min(xd), np.max(xd)))
ax1.plot(zAxisLine[0], zAxisLine[1], zAxisLine[2], color='black',zorder=1,alpha=0.5)
plt.tight_layout()

我已经生成了一个3D圆形平面,该平面已沿x轴旋转了45度:鉴于x和z坐标,我想确定该平面的y坐标,但我不知道如何...

python arrays numpy scipy interpolation
1个回答
0
投票

这是简单明了的3D解析几何。首先,请注意没有“圆平面”之类的东西;您已经描述了一个圆及其内部,根据定义,它们被嵌入到特定平面中。

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