【问题标题】:Get y coordinates given x and z for a plane in 3D在给定 x 和 z 的情况下获取 3D 平面的 y 坐标
【发布时间】:2026-02-23 11:40:01
【问题描述】:

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

在给定 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()

【问题讨论】:

  • 你是指磁盘还是平面?如果要查看 (x,z) 平面上的给定点是否可以映射到圆盘,则需要计算旋转圆盘在 (x-z) 平面上的阴影投影,然后确定您的候选点是否位于是否在那个阴影(椭圆)内。
  • 我是说磁盘。给定 3D 空间中的任何 (x,y,z) 坐标,我需要沿 y 轴从给定点到磁盘的距离。

标签: python arrays numpy scipy interpolation


【解决方案1】:

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

那个平面的方程是y + z = 0x 是一个不受约束的变量,除了用于定义圆的边界。

因此,您的问题简化为

y = -z

【讨论】:

    【解决方案2】:

    首先,生成旋转圆盘投影到 x-z 平面上的椭圆:

    https://math.stackexchange.com/questions/2388747/formula-for-ellipse-formed-from-projecting-a-tilted-circle-onto-the-xy-plane

    因为磁盘倾斜了 45 度,所以这种情况要容易一些。椭圆的长轴就是原盘的直径,短轴与直径有diameter**2 = 2 * (minor**2)相关。

    一旦你有了这个椭圆的长轴和短轴,就很容易确定测试点的 x、z 分量是否位于该椭圆内,使用以下等式:

    https://math.stackexchange.com/questions/76457/check-if-a-point-is-within-an-ellipse

    如果测试点位于圆盘内,则圆盘上的 y 分量如上述答案中所述(仅适用于 45 度倾斜,但它只是一个直角三角形):y = -z 您现在已经在 x-y-z 空间中找到了位于旋转磁盘上的点,因此只需从测试点的 y 值中减去该 y 值即可确定沿 y 轴到磁盘的距离。

    【讨论】:

      最近更新 更多