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

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

问题描述

我想使用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天全站免登陆