How to obtain the angle that the plane fitted to a group of points forms with the vertical (z-axis)

Viewed 31

I am trying to calculate first of all, the plane that fits a group of points in 3 dimensions, this I have done with the following code:

import numpy as np
import scipy.linalg

# Create some 3-dim points
mean = np.array([0.0,0.0,0.0])
cov = np.array([[1.0,-0.5,0.8], [-0.5,1.1,0.0], [0.8,0.0,1.0]])
data = np.random.multivariate_normal(mean, cov, 50)

#Fit plane
C,_,_,_ = scipy.linalg.lstsq(np.c_[data[:,0], data[:,1], np.ones(data.shape[0])], data[:,2])

# Coefficients in the form: a*x + b*y + c*z + d = 0.
a, b, c, d = C[0], C[1], -1., C[2]

But once I have the coefficients of the plane, how can I know the angle that the plane makes with the vertical? Thanks!

1 Answers

A vector perpendicular to a plane

ax+by+cz=d

is given by (a,b,c).

Now, the angle between two planes is the acute angle between two normal vectors, so:

v1=[a,b,c]
v2=[0,0,1]

angle = np.arccos(np.dot(v1, v2) / (np.linalg.norm(v1) * np.linalg.norm(v2)))
Related