【问题标题】:Plotting a plane and its normal绘制平面及其法线
【发布时间】:2020-08-14 21:24:32
【问题描述】:

我有一个平面的法线和一个位于它上面的点。我试图将这两个都画出来,但我认为这不是正确的,我不知道为什么。这是我的代码。

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

point  = np.array([1309.66102863, -531.22959263,  341.89779288])
normal = np.array([ 80.60165306, -32.69394323,  21.04172506])

# a plane is a*x+b*y+c*z+d=0
# [a,b,c] is the normal. Thus, we have to calculate
# d and we're set
d = -point.dot(normal)

# create x,y
xx, yy = np.meshgrid(range(1200,1400), range(-600,-400))

# calculate corresponding z
z = (-normal[0] * xx - normal[1] * yy - d) * 1. /normal[2]

# plot the surface
plt3d = plt.figure().gca(projection='3d')
plt3d.plot_surface(xx, yy, z, alpha=0.2)
plt3d.plot([point[0], point[0]+normal[0]], 
           [point[1], point[1]+normal[1]], 
           [point[2], point[2]+normal[2]])
plt.show()

我从this 帖子修改了它。我得到的结果是这样的 -

显然法线不垂直于平面。

但有时它会起作用,例如当我设置时

point  = np.array([1, 2, 3])
normal = np.array([1, 1, 2])

我得到的情节是

显然这要好得多。在第一种情况下它怎么不起作用?

【问题讨论】:

    标签: python numpy matplotlib plot linear-algebra


    【解决方案1】:

    由于轴的纵横比,它看起来很奇怪。

    如果您将每个轴的范围限制设置为 1:1:1,它将看起来垂直。

    以下是同一“角度”的 1:1 而非 1:1 范围限制的示例:

    【讨论】:

      猜你喜欢
      • 2021-07-05
      • 2018-03-12
      • 2023-02-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-14
      • 1970-01-01
      相关资源
      最近更新 更多