Find nearest position on a geometry
-
Hello,
is there a handy API function to find the nearest position on a geometry to a given point position?
I would like to be able to specify a position in space and get the nearest position on the surface of a polygon object.
Thanks & greetings,
Frank -
Hi,
I am not quite sure what you would consider handy, but the C++ API exposes a KD-Tree type. Read its manual here. The closest point lies then on one of the polygons associated with that vertex. One way to calculate it, could be to calculate the orthogonal projection of the point onto the plane of the polygon, convert that result into barycentric coordinates of that polygon and then zero out any component, that is smaller than zero.
Cheers
zipit -
Right, that would be a way, thanks.
I was hoping to be able to do it in Python for now, because it makes prototyping so much easier. Just to see if my idea is working at all. But since it's a shader project, I'd have to move to C++ anyway, for performance reasons.
I guess I'll try that.
-
@fwilleke80 said in Find nearest position on a geometry:
Right, that would be a way, thanks.
I was hoping to be able to do it in Python for now, because it makes prototyping so much easier. Just to see if my idea is working at all. But since it's a shader project, I'd have to move to C++ anyway, for performance reasons.
I guess I'll try that.
You do not have to tell me that Not a big fan of C++ here
-
I personally love C++ and wouldn't change my main programming language to anything else. But I have to admit that Python is quite handy for quick prototyping (though the missing debugging capabilities in Cinema really suck for bigger Python projects).
-
Hi Frank, thanks for reaching out us.
With regard to your request, aside from confirming that nothing comes with Python API for obvious performance reasons, in C++ the nearest thing you can find is KDtree - as already pointed out by @zipit - or other similar accelerating structures.
On top of these notes, I would consider this topic more a general programming / algorithm-related topic which could find, based on the contour conditions, different "better" solutions.Best, R