Find closest point, on closest curve c#

Hi
I would use RTree class for this.

  1. Find BoundingBoxes (BB) for each object (curve)
  2. Populate RTree with these BB
  3. Call RTree.Search method on theses set with parameter BounidingBox which I would set to be bounding box between my testing pint and a point on lets say first object in the list of objects to test
  4. by calling Search method event will fire for every intersection of testing bounding box with BBoxes and callback method will be called for every event fired
  5. So you create your calback method where you can shrink testing bounding box by using some logic (origin of scale is your testing point), lets say by scale 0.5 size, and than search again (e.cancel has to be set to true in callback methot to stop testing other BB)
  6. If there is no intersection of BB and testing boxes than you should go back and enalrge testing box with scale factor 1.25 of actual size and RTree.Search againn
  7. You stop when scale change becomes small (you have to decide what it will be)
  8. You have to remember last boundong for which fire event occurs and than by using Rtree.Search with different callback method where you test for closest point of each object
  9. There is code for testing MashMash Collison where I use RTree for it,
    see my post at this topic
    Intersection.MeshMeshFast faster method?

If you need any further help let me know
Regards
Radovan

1 Like