int closestVert = 0;float closestDist = 100000000.0f; //Arbitraty large numberPoint3 pos(0,0,0); //The position to compare withfor (int i=0;i<numVerts;i++){ Point3 v = vertPos - pos; float dist = (v.x * v.x) + (v.y * v.y) + (v.z * v.z); //Squared distance if (dist < closestDist) { closestDist = dist; closestVert = i; }}
How to find nearest vertex of a mesh to some other point?
A straightforward way to do without using any sqrt it would be:
Maybe you can get it faster with a bit preprocessing. Some time ago I saw an approach, used in ASSIMP. They used an arbitrary plane to create a sorted list (the sort key was the distance of vertex to plane), after the list is created you simply take the distance of your reference vertex to the plane and search the closest entry, since the list is sorted you can do a binary search to gather some speed.
Is the mesh convex or concave?
If it's convex then it's simple. Pick a vertex and walk towards the point you want to go to. That is walk in the direction of smaller distance. You'll find the point much faster then comparing all distances.
You will have to maintain connectivity in your mesh though.
Concave walking can also be done but it is a little more complicated.
-= Dave
If it's convex then it's simple. Pick a vertex and walk towards the point you want to go to. That is walk in the direction of smaller distance. You'll find the point much faster then comparing all distances.
You will have to maintain connectivity in your mesh though.
Concave walking can also be done but it is a little more complicated.
-= Dave
Quote:Original post by ryt
I dont understand why do you put this in dot_product()? I understand why are you subtracting, so you could get a vector from mesh_pt to other_pt and with other code I see what are you trying to accomplish.
dot(a,b){ return a.x*b.x + a.y*b.y + a.z*b.z;}lengthSquared(a){#if 0 return a.x*a.x + a.y*a.y + a.z*a.z;#else // or.... return dot(a,a);#endif}length(a){ return sqrt( lengthSquared(a,a) );}
if you're trying to deform mesh A based on proximity to a plane then do it in the vertex shader.
Use the planar distance and smoothstep towards the centre of the model along the normal to the vertex... this will also give you a "bouncy" look.
Use the planar distance and smoothstep towards the centre of the model along the normal to the vertex... this will also give you a "bouncy" look.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement