# Nearest point on boundary to exterior point

**URL:** https://fenicsproject.discourse.group/t/nearest-point-on-boundary-to-exterior-point/6687
**Category:** Uncategorized
**Created:** [September 27, 2021, 11:16pm UTC](https://fenicsproject.discourse.group/t/nearest-point-on-boundary-to-exterior-point/6687 "2021-09-27T23:16:48Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![kamensky](https://avatars.discourse-cdn.com/v4/letter/k/e95f7d/32.png) [@kamensky](https://fenicsproject.discourse.group/u/kamensky)
#### Post date: [September 28, 2021, 4:05pm UTC](https://fenicsproject.discourse.group/t/nearest-point-on-boundary-to-exterior-point/6687/2 "2021-09-28T16:05:02Z")

</div>

I don’t know of any built-in functionality for this. I did think of a somewhat-involved workaround:

- Define a CG1 scalar space, `V = FunctionSpace(mesh,"CG",1)`.
- Find the index of the closest cell to `x` in `mesh` using the `compute_first_entity_collision` method of `mesh.bounding_box_tree()`.
- Use some DoF maps for `V` and `V.element().evaluate_basis` to evaluate all shape functions on that cell. The shape function that is negative is the one whose node is the vertex “opposite” `x`.
- Get that shape function’s gradient with `V.element().evaluate_basis_derivatives`.
- Given `x`, the shape function evaluation at `x`, and the shape function gradient, you can do some algebra to calculate the closest point to `x` on the cell (where the shape function goes to zero along a line through `x` in the direction of the gradient).

For an example of how to use the basis function evaluation functions, you might take a look at [this discussion](https://fenicsproject.discourse.group/t/accessing-the-basis-function-of-a-finite-element/2426).

---

_[View the full topic](https://fenicsproject.discourse.group/t/nearest-point-on-boundary-to-exterior-point/6687)._
