# Using VTK to implement particle transport grometry (question about celllocator,IntersectWithLine)

**URL:** https://discourse.vtk.org/t/using-vtk-to-implement-particle-transport-grometry-question-about-celllocator-intersectwithline/12887
**Category:** Development
**Created:** [December 12, 2023, 9:14pm UTC](https://discourse.vtk.org/t/using-vtk-to-implement-particle-transport-grometry-question-about-celllocator-intersectwithline/12887 "2023-12-12T21:14:24Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Rafael\_Scatena](https://discourse.vtk.org/user_avatar/discourse.vtk.org/rafael_scatena/32/7820_2.png) [@Rafael\_Scatena](https://discourse.vtk.org/u/Rafael_Scatena)
#### Post date: [December 12, 2023, 9:14pm UTC](https://discourse.vtk.org/t/using-vtk-to-implement-particle-transport-grometry-question-about-celllocator-intersectwithline/12887/1 "2023-12-12T21:14:24Z")

</div>

I am building a geometry module to my particle transport program.  
Contrary to rendering and visualization, particle transport moves the particle a little bit each time and check if it has crossed the mesh. My question is if I need to load only the triangles close to the particle or should I load all of them.

I build a code that loads only the triangle cells in the boulding box ahead of the particle as an optimization. Is the optimization ok? Should I further optimize the code? Or should I discard all optimizations and let vtk load all triangles?

Thank you

vtkIdList\* cellsWithinBounds = FindCellsInBoundingBox(resultPoint, bbdiameter);

```
 // Create a list to store intersection distances
 std::vector<std::pair<double, vtkIdType>> intersections;

// Process the found cell IDs as needed
for (vtkIdType i = 0; i < cellsWithinBounds->GetNumberOfIds(); ++i)
{
    vtkIdType cellId = cellsWithinBounds->GetId(i);

    vtkCell* cell = polyData->GetCell(cellId);

    if (cell) {
            // Access the intersection point
            double intersectionPoint[3];
            double pcoords[3];
            double weights[3];
            double tolerance = 1e-6; // Adjust tolerance as needed

            // Find the intersection point on the triangle
            if (triangle->IntersectWithLine(startPoint, resultPoint, tolerance, intersectionPoint, pcoords, weights)) {
             // Calculate the distance between the query point and the intersection point
             double distance = vtkMath::Distance2BetweenPoints(startPoint, intersectionPoint);

                // Store the distance and cell ID in the list
                intersections.emplace_back(distance, currentCellId);
            }
        }
    
    }

```
