Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the tilt angle of a plane defined by three coordinates in python?

Given three coordinates (each with x, y and z value), how can I use numpy and/or scipy to calculate the tilt (or inclination) of the resulting plane?

a = np.array([32.49, -39.96,-3.86])

b = np.array([31.39, -39.28, -4.66])

c = np.array([31.14, -38.09,-4.49])

I want to use this calculations to filter a LiDAR point cloud dataset for roof segments. So the roofs have angles like between 30 and 60 degree.

I know that I would have to rotate the planes defined by the three coordinates to calculate the desired angles but I have no clue how this can be achieved with numpy/scipy. What I probably need is a rotation like this:

enter image description here enter image description here

UPDATE:

Paul Panzers answer makes it possbible to calculate the planes angles with each axis. But how am I able to rotate the plane so that I get angles comparable on one axis for multiple triplet point sets? My main goal: I want to build triangles of each roof point using the two nearest neighbor points and calculate those angles. If there are like 50% angles between 30 and 60 degreee the roof gets classified as gable for example.

like image 518
conste Avatar asked Oct 17 '25 08:10

conste


1 Answers

Take the cross product of two differences of your three vectors, for example

n = np.cross(b-a, c-a)

This will give you a normal vector to your plane. Its angle with any of the coordinate planes will sum to pi/2 with the angle of your plane with the same coordinate plane.

To calculate the angle between the normal vector and a coordinate plane just normalise and take the arc sin of the corresponding component

nn = n / np.linalg.norm(n)
angles = np.abs(np.arcsin(nn))
like image 183
Paul Panzer Avatar answered Oct 19 '25 22:10

Paul Panzer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!