1 year ago

#340149

test-img

xairopro

Surface Equation

I want a set of 3D points and I want to find the equation that they describe. Something like z = f(x, y). The surface fitting method I am using is this one:

X,Y = np.meshgrid(np.arange(0,2,0.5), np.arange(0,2,0.5))
XX = X.flatten()
YY = Y.flatten()

 # best-fit quadratic curve
A = np.c_[np.ones(capo_mesh.shape[0]), capo_mesh[:,:2], np.prod(capo_mesh[:,:2], axis=1), capo_mesh[:,:2]**2]
C,_,_,_ = scipy.linalg.lstsq(A, capo_mesh[:,2])

# evaluate it on a grid
Z = np.dot(np.c_[np.ones(XX.shape), XX, YY, XX*YY, XX**2, YY**2], C).reshape(X.shape)


# plot points and fitted surface
fig = plt.figure()
ax = plt.axes(projection='3d')
ax.plot_surface(X, Y, Z, rstride=1, cstride=1, alpha=0.2)
ax.scatter(capo_mesh[:,0], capo_mesh[:,1], capo_mesh[:,2], c='r', marker=".")
plt.xlabel('X')
plt.ylabel('Y')
ax.set_zlabel('Z')
ax.axis('auto')
ax.axis('tight')
plt.show()

which I took from this thread: https://gist.github.com/raacampbell/1c8db957d4f4620c60c3b41e8831d536

As long as I understand, the scipy.linalg.lstsq function stores in C the values of the coefficients. If I do print(C) it gives me the following:

[-4.79585721e-02  1.48075202e-01  4.61947721e-01  1.22189838e-04
 -8.75774625e-02 -1.55696550e-01]

How do I transform those points to an equation z = f(x, y)?

python

surface

0 Answers

Your Answer

Accepted video resources