用 matplotlib 绘制的相交平面之间的角度

Angle between intersecting planes drawn with matplotlib

我需要制作一个具有相交平面的图,类似于问题中提出的图:How to draw intersecting planes?. The accepted answer in that question is a great piece of code by tcaswell(代码在下面)。

在该代码中,使用了一个变量 angle,它显然控制了每个平面之间的角度。对于较小的值,它肯定会这样,但对于较大的值,它不会。

例如,这些是值 angle = 0.25, 0.5, 1, 5, 50, 100.

的结果

变量显然对平面之间的角度有影响,但它也控制倾斜平面的延伸。起初我虽然 angles 是以弧度表示的,但事实并非如此。它也没有以度数表示,如上图所示,平面之间似乎永远不会达到 90º 角。

接下来的问题是:那个变量在做什么?,以及:我怎样才能控制平面之间的角度?


代码:

from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np


fig = plt.figure()
ax = Axes3D(fig)

dim = 10

# Define x,y plane.
X, Y = np.meshgrid([-dim, dim], [-dim, dim])
Z = np.zeros((2, 2))

# Define inclined plane.
angle = 0.5  # <-- This is the variable
X2, Y2 = np.meshgrid([-dim, dim], [0, dim])
Z2 = Y2 * angle
X3, Y3 = np.meshgrid([-dim, dim], [-dim, 0])
Z3 = Y3 * angle

# Plot x,y plane.
ax.plot_surface(X, Y, Z, color='gray', alpha=.5, linewidth=0, zorder=1)
# Plot top half of inclined plane.
ax.plot_surface(X2, Y2, Z2, color='blue', alpha=.5, linewidth=0, zorder=3)
# Plot bottom half of inclined plane.
ax.plot_surface(X2, Y3, Z3, color='blue', alpha=.5, linewidth=0, zorder=-1)

ax.set_xlim(-10., 10.)
ax.set_ylim(-10., 10.)
ax.set_zlim(-10., 10.)
plt.show()

所谓的angle只是y-coordinate的乘数。所以对于小 角度 结果是相同的,然而,对于 90 度旋转,该因子必须是无穷大。

您可以使用 tanget 重新定义角度并提供以弧度为单位的输入:

angle = np.tan(pi * 0.25)

现在,您将看到一个指定角度的实际旋转。


更清晰的修改可能是:

# Define inclined plane.
angle = pi * 0.5  # <-- This is the variable
X2, Y2 = np.meshgrid([-dim, dim], [0, dim])
Z2 = Y2 * np.tan(angle)
X3, Y3 = np.meshgrid([-dim, dim], [-dim, 0])
Z3 = Y3 * np.tan(angle)