Python – (num)pythonic method to make 3D meshes for line drawing

(num)pythonic method to make 3D meshes for line drawing… here is a solution to the problem.

(num)pythonic method to make 3D meshes for line drawing

I want to create a line between two points in 3D space:

origin = np.array((0,0,0),'d')
final = np.array((1,2,3),'d')
delta = final-origin
npts = 25
points np.array([origin + i*delta for i in linspace(0,1,npts)])

But this is silly: I build a big python list and then pass it to numpy, when I was sure there was a way to use numpy alone. How does the numpy wizard do something like this?

Solution

You can eliminate all Python loops for this loop with a little broadcast:

origin + delta*np.linspace(0, 1, npts)[:, np.newaxis]

Related Problems and Solutions