I'd like to find an object / surface normal (tangent vector) for a given point in space. More in detail I have an object and a spline following the objects surface and I want to get the object normal for each spline point.
I couldn't find a way how to approach this, yet ....
Maybe someone has a tip or an idea?
(I want to do this in python)
Hi @indexofrefraction unfortually the Python Cinema 4D API does not provide any way to easily find an object/surface normal for a given point in space.
One things could be to use a c4d.utils.GeRayCollider to retrieve the polygon attached to the point and then compute yourself the surface normal.
Another way would be to create a KdTree and retrieve the nearest point and compute this tangent vector yourself.But there is no KdTree in the Python Cinema 4D SDK, so you will need to build it yourself.
hm.. looking at c4d.utils.GeRayCollider ...
is it correct that i always have to define a ray vector ?
as i understand it GetNearestIntersection() is just the nearest intersection with the given vector, right?
is possible to eval the nearest intersection between a point and an object without vector?
or is that what KdTree is used for ?
as a disclaimer upfront, this is a private posting of mine, your case is still being handled by @m_adam.
When I see your case correctly, you are interested in the point p and its normal n on a polygonal mesh M that is closest to a given point q on a spline S. Or in short, you are interested in the projection of q onto M. Ray-casting, e.g., GeRayCollider, will not help you much here I would say, since coming up with a ray-casting direction is the same problem as the one you are trying to solve; as you already did find out yourself.
Cinema 4D's Python SDK has no projection helper class, so, you would have to do that on your own. The general procedure would be:
For all that you do not need any fancy classes or libraries, but it can be a bit slow if you do this for very large meshes. The expensive part is the first step, finding the closest vertex v in M. Which is probably why Maxime mentioned kd-trees. They are a form Binary-Space-Partitioning, i.e., a performant way to find the closest point p out of a point cloud C for a query point q. Since the Cinema Python SDK has no kd-Tree, you would have to write your own BSP implementation, a octree would be enough in this case (which is effectively just a clever form of a 3D-lattice). But this is not really needed functionality-wise, it will just make your solution more performant.
that's a roadmap !!
gosh, it looks like i have quite some work ahead of me!
dunno yet, if i'm crazy enough to give it a try :))
ps. that also means that the nearest intersection between
a point and an object without vector is not possible with GeRayCollider (?)
without further questions or replies, we will consider this topic as solved by Thursday and flag it accordingly.
Thank you for your understanding,