matplotlib 未正确显示 3D 平面的交集 [英] matplotlib not displaying intersection of 3D planes correctly

查看:30
本文介绍了matplotlib 未正确显示 3D 平面的交集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想绘制两个平面并找到它们的相交线,但我得到了这个结果,无法判断它们相交的位置,因为一个平面覆盖另一个.

I want to plot two planes and find their intersection line, but I get this result, where it's impossible to tell where they intersect, because one plane overlays the other.

3D 投影应该隐藏平面的不可见部分,我如何使用 ma​​tplotlib 获得此结果?

A 3D projection should hide the non-visible part of the plane, how do I attain this result using matplotlib?

你可以清楚地看到这些到平原应该相交.

You can clearly see that these to plains should intersect.

这是我用来得到这个结果的代码

Here's the code I've used to get this result

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

values = range(-10, 11)

def plotPlane(plot, normal, d, values, colorName):
    # x, y, z
    x, y = np.meshgrid(values, values)
    z = (-normal[0] * x - normal[1] * y - d) * 1. / normal[2]

    # draw plot
    plot.plot_surface(x, y, z, color=colorName)

image = plt.figure().gca(projection='3d')

plotPlane(image, [3, 2, -4], 1, values, "red")
plotPlane(image, [5, -1, 2], 4, values, "gray")

plt.show()

推荐答案

参见 如何绘制相交平面? 详细解释 + 可能的解决方法.

See How to draw intersecting planes? for a long explanation + possible work around.

matplotlib 的 3D 支持的简短回答是巧妙地使用投影来生成 3D 对象的 2D 视图,然后将其渲染到画布上.由于 matplotlib 渲染(一次一位艺术家)的方式,一位艺术家要么完全高于另一位艺术家,要么完全低于另一位艺术家.如果您需要真正的 3D 支持,请查看 mayavi.

The short answer in that matplotlib's 3D support is clever use of projections to generate a 2D view of the 3D object which is then rendered to the canvas. Due to the way that matplotlib renders (artist at a time) one artist is either fully above or fully below another. If you need real 3D support look into mayavi.

这篇关于matplotlib 未正确显示 3D 平面的交集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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