例如,設 A 為 x,y,z 坐標位置,N_A 為法線。我需要繪制一個垂直于法線的平面,法線箭頭指向 3D
A = [0.960396491, 0.06136547597, -6.718505E-5]
N_A = [ -0.89169092, 0.02074738, -0.45216906]
uj5u.com熱心網友回復:
該plot_surface方法允許您繪制給定的表面xx, yy,zz網格。所以游戲的名稱是創建這些meshgrid物件。
法線(a, b, c)通過以下關系指定平面:ax by cz d = 0,我們可以通過簡單的算術確定平面上的d給定點(x, y, z)。給定任意選擇xx的和yy meshgrid物件,然后我們可以求解z以計算對應zz meshgrid的 和繪圖。

import numpy as np
import matplotlib.pyplot as plt
point = np.array([ 0.960396491, 0.06136547597, -6.718505E-5])
normal = np.array([-0.891690920, 0.02074738000, -0.45216906])
# A plane is given by
# a*x b*y c*z d = 0
# where (a, b, c) is the normal.
# If the point (x, y, z) lies on the plane, then solving for d yield:
# d = -(a*x b*y c*z)
d = -np.sum(normal * point)
# Create a meshgrid:
delta = 5
xlim = point[0] - delta, point[0] delta
ylim = point[1] - delta, point[1] delta
xx, yy = np.meshgrid(np.arange(*xlim), np.arange(*ylim))
# Solving the equation above for z:
# z = -(a*x b*y d) / c
zz = -(normal[0] * xx normal[1] * yy d) / normal[2]
fig = plt.figure()
ax = fig.add_subplot(projection='3d')
ax.plot_surface(xx, yy, zz, alpha=0.5)
# Plot point.
x, y, z = point
ax.plot(x, y, z, marker='o', markersize=10, color='red')
# Plot normal.
dx, dy, dz = delta * normal
ax.quiver(x, y, z, dx, dy, dz, arrow_length_ratio=0.15, linewidth=3, color='red')
# Enforce equal axis aspects so that the normal also appears to be normal.
ax.set_xlim(*xlim)
ax.set_ylim(*ylim)
zlim = point[2] - delta, point[2] delta
ax.set_zlim(*zlim)
# Label axes.
ax.set_xlabel('X', fontsize=20)
ax.set_ylabel('Y', fontsize=20)
ax.set_zlabel('Z', fontsize=20)
plt.show()
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/517321.html
標籤:matplotlib
上一篇:添加輪廓以并排繪制多個直方圖
