如何绘制相交的平面? [英] How to draw intersecting planes?

查看:17
本文介绍了如何绘制相交的平面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 matplotlib 或多或少地绘制我在下面附上的图形,其中包括两个具有适当透明度的相交平面,指示它们的相对方向,以及两个平面中以 2D 方式投影的圆和向量.

I want to use matplotlib to draw more or less the figure I attached below, which includes the two intersecting planes with the right amount of transparency indicating their relative orientations, and the circles and vectors in the two planes projected in 2D.

我不确定是否有用于执行此操作的现有软件包,有任何提示吗?

I'm not sure if there is an existing package for doing this, any hints?

推荐答案

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


fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

dim = 10

X, Y = np.meshgrid([-dim, dim], [-dim, dim])
Z = np.zeros((2, 2))

angle = .5
X2, Y2 = np.meshgrid([-dim, dim], [0, dim])
Z2 = Y2 * angle
X3, Y3 = np.meshgrid([-dim, dim], [-dim, 0])
Z3 = Y3 * angle

r = 7
M = 1000
th = np.linspace(0, 2 * np.pi, M)

x, y, z = r * np.cos(th),  r * np.sin(th), angle * r * np.sin(th)

ax.plot_surface(X2, Y3, Z3, color='blue', alpha=.5, linewidth=0, zorder=-1)

ax.plot(x[y < 0], y[y < 0], z[y < 0], lw=5, linestyle='--', color='green',
        zorder=0)

ax.plot_surface(X, Y, Z, color='red', alpha=.5, linewidth=0, zorder=1)

ax.plot(r * np.sin(th), r * np.cos(th), np.zeros(M), lw=5, linestyle='--',
        color='k', zorder=2)

ax.plot_surface(X2, Y2, Z2, color='blue', alpha=.5, linewidth=0, zorder=3)

ax.plot(x[y > 0], y[y > 0], z[y > 0], lw=5, linestyle='--', color='green',
        zorder=4)

plt.axis('off')
plt.show()

  • 我运行的版本与当前主版本非常接近,所以我不是确定什么可以在旧版本中使用

  • I am running a version very close to the current master, so I am not sure what will work in older versions

拆分绘图的原因是上方"和下方"是以某种神秘的方式确定的(我不确定 zorder 是否真的做了任何事情),并且实际上取决于绘制艺术家的顺序.因此表面不能相交(一个在每个地方都在另一个之上),因此您需要分别绘制相交两侧的部分.(你可以在我没有拆分的黑线中看到这一点,看起来像是在上蓝色平面的顶部").

The reason for splitting up the plotting is that 'above' and 'below' are determined in a some what arcane way (I am not strictly sure the zorder actually does anything), and is really dependent on the order the artists are drawn in. Thus surfaces can not intersect (one will be above the other every where), so you need to plot the sections on either side of the intersection separately. (You can see this in the black line which I didn't split at looks like it in 'on top of' the upper blue plane).

表面的正确"排序似乎也取决于视角.

The 'proper' ordering of the surfaces also seems to be dependent on the view angle.

这篇关于如何绘制相交的平面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆