I have an arbitrary oriented plane and an object "above" it.
I would like to calculate the distance from the plane for each vertex in that object.
I suppose some kind of a transformation of vertex global coordinates to the local orientation of the plane would be the way to go, however, I'm too new to Blender to know even what to search for (I did try searching for mentioned keywords but didn't find something I could figure out, unfortunately).
I know how to iterate trough vertices of an object and get global coordinates, no problems with that.
As Chebhou suggested I tried using the
mathutils.geometry.distance_point_to_plane(pt, plane_co, plane_no) but cannot get it to work.
For testing I'm using a 2x2x2 cube at (0,0,1) and 6x6x6 plane at (0,0,0):
The code is this (shortened for clarity):
point_location = thecube.location planepoint_location_w = theplane.matrix_world * theplane.data.vertices.co plane_normal = theplane.matrix_world * theplane.data.polygons.normal distance = geometry.distance_point_to_plane(point_location, planepoint_location_w, plane_normal) print("point_location = ", point_location) print("planepoint_location_w = ", planepoint_location_w) print("distance = ", distance)
The result for the cube and plane location as in the pic is OK (the point is 1 unit above the plane):
point_location = <Vector (0.0000, 0.0000, 1.0000)> planepoint_location_w = <Vector (-3.0000, -3.0000, 0.0000)> distance = 1.0
However, if I move the plane on Y axis to (0,1,0) the result is this (but should be the same as before):
point_location = <Vector (0.0000, 0.0000, 1.0000)> planepoint_location_w = <Vector (-3.0000, -2.0000, 0.0000)> distance = 2.1213202476501465
Obviously I'm doing something wrong - but what?