# Closest point query¶

The closest point operator finds the point on a triangle that is closest to a query point. Query point \(o\) (shown in dark blue), at the origin, is closest to point \(o'\) (light blue), which lies in the triangle’s interior. Query point \(a\) (olive) is closest to point \(a'\) (yellow), which lies on the triangle’s edge at a vertex.

```
#include "axom/primal/operators/closest_point.hpp"
```

```
TriangleType tri(PointType {1, 0, 0}, PointType {0, 1, 0}, PointType {0, 0, 1});
PointType pto = PointType {0, 0, 0};
PointType pta = PointType {-1, 2, 1};
// Query point o lies at the origin. Its closest point lies in the
// interior of tri.
PointType cpto = closest_point(pto, tri);
// Query point a lies farther from the triangle. Its closest point
// is on tri's edge.
int lcpta = 0;
PointType cpta = closest_point(pta, tri, &lcpta);
```

As the code example shows, `closest_point()`

can take a pointer to an `int`

as an optional third parameter. If supplied, the function writes a value into
the `int`

that indicates which of the triangle’s vertices or sides contains
the closest point (or the interior).