# Calculate distance from point to Face

I want to measure the distance from a point to the Face along the model Z-axis.
The red Face is in a CCW rotated component.

With the distance_to_plane method I get the value from point1 perpendicular to the Face (pink line).

``````point1 = Geom::Point3d.new(235.mm,0,0)
plane = [Geom::Point3d.new(1000.mm,0,0), [-0.8682431421244594, 0.0, -0.4961389383568334]]
distance = point1.distance_to_plane(plane).to_mm
# 664.2060037252114
``````

I prefer not to use raytest because there may be objects in the model that can cause incorrect raytests.

What is the easiest way to measure the distance between point1 and the Face along the model Z-axis?
Is there a way to determine the distance_to_plane direction that the method should measure?

I guess you mean perpendicular to the face, a typo.

And here the local (componentâ€™s) Z-axis?

Fixed the typos @Wo3Dan.

I want to measure the distance from a point to the Face along the model Z-axis.
Not the local componentâ€™s Z-axis.

Probably this would be to use: `Geom::intersect_line_plane()`

â€¦ where the 1st argument is: `line1 = [point1, Z_AXIS]` â€¦
and the 2nd plane argument would be the `face.plane` converted to the same coordinate system as `point1` is expressed in (likely in the modelâ€™s coordinates.)

I would expect that `face.plane` would return values in the componentâ€™s local coordinates, unless the `active_entities` are the component instance, (in which case the API will return values in model coordinates.)

Anyway, once you have the intersection point use `point1.distance(intersect_point)`.

2 Likes

From the top of my head: If you know the angle between the blue and the pink one, the blue distance is acos(angle) Ă— pink_length

Or was it pink_length / acos(angle)

Anyhow some good old Pythagoras: Pythagorean theorem - Wikipedia

2 Likes