# Find the nearest triangle from a selected point

**URL:** <https://discourse.vtk.org/t/find-the-nearest-triangle-from-a-selected-point/9837>\
**Category:** Development\
**Created:** [November 16, 2022, 1:29pm UTC](https://discourse.vtk.org/t/find-the-nearest-triangle-from-a-selected-point/9837 "2022-11-16T13:29:53Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Henrik](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/h/ba9def/32.png) [@Henrik](https://discourse.vtk.org/u/Henrik)\
**Post date:** [November 16, 2022, 1:29pm UTC](https://discourse.vtk.org/t/find-the-nearest-triangle-from-a-selected-point/9837/1 "2022-11-16T13:29:53Z")

</div>

Hey guys,  
i’m very new into VTK and using the 5.8. I already archieved to build a small 3D Plotter to open and view some .stl files. Now i’m trying to implementate a function that calculates me the nearest triangle from a selected point. I have red nearly everything about vtk on google, but still didnt find anything.  
Maybe some of you can help me with this task.  
Thank you so much!

---

<div class="post-metadata">

**Author:** ![will.schroeder](https://discourse.vtk.org/user_avatar/discourse.vtk.org/will.schroeder/32/233_2.png) [@will.schroeder](https://discourse.vtk.org/u/will.schroeder)\
**Post date:** [November 16, 2022, 1:40pm UTC](https://discourse.vtk.org/t/find-the-nearest-triangle-from-a-selected-point/9837/2 "2022-11-16T13:40:22Z")

</div>

Depending on your application, this may be easy or complex 🙂

I would start with vtkDataSet::FindCell() and its cousins. Note that this virtual method is implemented in vtkDataSet derived classes (e.g., vtkPointSet::FindCell()) so you may want to poke around to learn more depending on the particulars of your data.

Now, if performance is a big concern, you need to become familiar with the cell locators (e.g., vtkCellLocator, vtkStaticCellLocator, etc. subclasses of vtkAbstractCellLocator).

Finally, if you want a trip down a deep rabbit hole, check out vtkFindCellStrategy class - some serious expertise is required to make sense of this.

---

<div class="post-metadata">

**Author:** ![Henrik](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/h/ba9def/32.png) [@Henrik](https://discourse.vtk.org/u/Henrik)\
**Post date:** [November 16, 2022, 1:43pm UTC](https://discourse.vtk.org/t/find-the-nearest-triangle-from-a-selected-point/9837/3 "2022-11-16T13:43:19Z")

</div>

Thank you for your answer! I really hoped there is a library for it. I code it with C# and thought there is a function, that shows me the nearest triangle of my point 😃

---

<div class="post-metadata">

**Author:** ![will.schroeder](https://discourse.vtk.org/user_avatar/discourse.vtk.org/will.schroeder/32/233_2.png) [@will.schroeder](https://discourse.vtk.org/u/will.schroeder)\
**Post date:** [November 16, 2022, 1:48pm UTC](https://discourse.vtk.org/t/find-the-nearest-triangle-from-a-selected-point/9837/4 "2022-11-16T13:48:30Z")

</div>

You may want to check out ParaView. Its interactive point/cell/data interrogation capabilities are quite nice.

---

<div class="post-metadata">

**Author:** ![Henrik](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/h/ba9def/32.png) [@Henrik](https://discourse.vtk.org/u/Henrik)\
**Post date:** [November 16, 2022, 1:53pm UTC](https://discourse.vtk.org/t/find-the-nearest-triangle-from-a-selected-point/9837/5 "2022-11-16T13:53:18Z")

</div>

Thank you, but i have to code it for myself. Can i use the FindCell() with an if condition or how does it work?

---

<div class="post-metadata">

**Author:** ![will.schroeder](https://discourse.vtk.org/user_avatar/discourse.vtk.org/will.schroeder/32/233_2.png) [@will.schroeder](https://discourse.vtk.org/u/will.schroeder)\
**Post date:** [November 16, 2022, 2:14pm UTC](https://discourse.vtk.org/t/find-the-nearest-triangle-from-a-selected-point/9837/6 "2022-11-16T14:14:05Z")

</div>

Given my schedule, the best I can recommend is to look at code examples. Other community members may be able to help, and of course Kitware pays the bills with support contracts (among other things :-))
