# Given an coordinate of point p, how to define which cell it is in?

**URL:** https://fenicsproject.discourse.group/t/given-an-coordinate-of-point-p-how-to-define-which-cell-it-is-in/12315
**Category:** General
**Created:** [September 28, 2023, 1:42am UTC](https://fenicsproject.discourse.group/t/given-an-coordinate-of-point-p-how-to-define-which-cell-it-is-in/12315 "2023-09-28T01:42:10Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![xi\_wang](https://avatars.discourse-cdn.com/v4/letter/x/8c91f0/32.png) [@xi\_wang](https://fenicsproject.discourse.group/u/xi_wang)
#### Post date: [September 28, 2023, 1:42am UTC](https://fenicsproject.discourse.group/t/given-an-coordinate-of-point-p-how-to-define-which-cell-it-is-in/12315/1 "2023-09-28T01:42:10Z")

</div>

One way that comes to my mind is to iterate through cells, and use vertices coordinates to compute if the given coordinate of p, but the implementation is different for different cell types, and will need the correct continuous order of vertices of a cell. Is there any more convenient way? It surely will be necessary if I want to decide which element to do integration when applying boundary forces.

---

<div class="post-metadata">

### Author: ![dokken](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/dokken/32/1560_2.png) [@dokken](https://fenicsproject.discourse.group/u/dokken)
#### Post date: [September 28, 2023, 4:19am UTC](https://fenicsproject.discourse.group/t/given-an-coordinate-of-point-p-how-to-define-which-cell-it-is-in/12315/2 "2023-09-28T04:19:43Z")

</div>

There are functions such as `compute_closest_entity` that uses bounding box trees for fast searching. This works even if the point is not in any cell.

There are other collision detection algorithms in DOLFIN/DOLFINx as well, but as you haven’t specified what version you are using I won’t go into details

---

<div class="post-metadata">

### Author: ![xi\_wang](https://avatars.discourse-cdn.com/v4/letter/x/8c91f0/32.png) [@xi\_wang](https://fenicsproject.discourse.group/u/xi_wang)
#### Post date: [September 28, 2023, 6:45am UTC](https://fenicsproject.discourse.group/t/given-an-coordinate-of-point-p-how-to-define-which-cell-it-is-in/12315/3 "2023-09-28T06:45:14Z")

</div>

Oh, sorry, I am using Dolfin. What function could I use if I want precise judgement of whether a point is inside an element?

---

<div class="post-metadata">

### Author: ![dokken](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/dokken/32/1560_2.png) [@dokken](https://fenicsproject.discourse.group/u/dokken)
#### Post date: [September 28, 2023, 6:47am UTC](https://fenicsproject.discourse.group/t/given-an-coordinate-of-point-p-how-to-define-which-cell-it-is-in/12315/4 "2023-09-28T06:47:22Z")

</div>

See; [How to determine whether a point belongs to a mesh cell - #2 by dokken](https://fenicsproject.discourse.group/t/how-to-determine-whether-a-point-belongs-to-a-mesh-cell/6857/2)
