How to get distance of vertices from an arbitrary plane in Python? 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.

Hopefully this screenshot illustrates the idea (the purple line would be the distance of one of the vertices):


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.

Edit:
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[0].co

plane_normal = theplane.matrix_world * theplane.data.polygons[0].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 =  &lt;Vector (0.0000, 0.0000, 1.0000)&gt;  
planepoint_location_w =  &lt;Vector (-3.0000, -3.0000, 0.0000)&gt;  
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 =  &lt;Vector (0.0000, 0.0000, 1.0000)&gt;
planepoint_location_w =  &lt;Vector (-3.0000, -2.0000, 0.0000)&gt;
distance =  2.1213202476501465


Obviously I'm doing something wrong - but what?
You can use the dedicated function :mathutils.geometry.distance_point_to_plane(pt, plane_co, plane_no) were you supply the plane normal and one point from it, and the point you want to calculate the distance to as in the following example :

import bpy
import mathutils

plane = bpy.context.scene.objects['Plane']
p1 = plane.matrix_world*plane.data.vertices[0].co
p2 = plane.matrix_world*plane.data.vertices[1].co
p3 = plane.matrix_world*plane.data.vertices[2].co
plane_no = mathutils.geometry.normal([p1, p2, p3])

obj = bpy.context.object
mat = obj.matrix_world

for v in obj.data.vertices:
    pt = mat*v.co
    d = mathutils.geometry.distance_point_to_plane(pt, p1, plane_no)
    print(round(d, 4))