Reputation: 61
I am using python to display some 3D points, and I have the x-y-z coordinates of all the points as well as their (unit) normal vector coordinates.
I have plotted the 3D points, but I don't know how to plot normal vectors.
Some code snippets are:
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import axes3d
# P contains point coordinates and normal vector coordinates
def drawPoints(P):
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1, facecolor="1.0")
ax = fig.gca(projection='3d')
x = P[:, 0]
y = P[:, 1]
z = P[:, 2]
ax.scatter(x, y, z, alpha=0.8, color="red", edgecolors='none', s=5)
nv_x = P[:, 3]
nv_y = P[:, 4]
nv_z = P[:, 5]
# I don't know how to draw normals
plt.show()
My desired result is to display the normal vector of on the top of each vertex. Thank you!
Upvotes: 2
Views: 2149
Reputation: 61
Like @Scott said, we can use mayavi
to visualize it.
from mayavi.mlab import *
def displayPointsAndNormals(P, N):
x = P[:, 0]
y = P[:, 1]
z = P[:, 2]
points3d(x, y, z, color=(0, 1, 0), scale_factor=0.01)
u = N[:, 0]
v = N[:, 1]
w = N[:, 2]
quiver3d(x, y, z, u, v, w)
show()
The result is like:
The data is taken from this repository.
Upvotes: 1