# Distance to closest point on ofPlanePrimitive

Hello!
I’m trying to figure out how to calculate the distance from a given point `p` to a plane defined as a `ofPlanePrimitive`.

There’s the geometric solution, by which I need to find the normal of the plane N=(A,B,C), and our target point p = (x_1, y_1, z_1).
From the normal, the plane can be defined as
equation for the plane as `Ax+By+Cz+D=0`, where `D = -Ax_0 - By_0 - Cz_0` (in my case, D is zero).

The distance formula is then the length of the projection of P onto the plane N:
`d = |p · N|`
So far so good.

But how do I get the normal from the plane? It seems like there should be an easy way to do this in OF, but I’m not seeing it in the docs.

Hello and welcome to the forum.
Those two functions should do what you need:
https://openframeworks.cc/documentation/glm/gtx_intersect/#!show_glm::intersectRayPlane

https://openframeworks.cc//documentation/math/ofVec3f/#!show_distance

HTH

ofPlanePrimitive extends ofNode and the plane mesh is formed along the x and y axis. The z axis should be the normal.
The `getZAxis()` function from ofNode should be the normal to the plane.
https://openframeworks.cc//documentation/3d/ofNode/#!show_getZAxis

1 Like

Awesome, this was the thing I needed, thank you!