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

查看:147
本文介绍了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投影应隐藏飞机的不可见部分,如何使用 matplotlib 获得此结果?

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天全站免登陆