Hi Uwe, That's exactly the problem I have solved. I wanted to project points into a 3d mesh, so I have to know the projected coordinates. It's important to note that, to test the point to point distance is very fast, but to test point to triangle in the space is slow and depending on the method it can be terrible slow. I see you mesh is very regular, so I believe you can use the same solution as mine. I have done everything by hand without numpy because I had problems working with numpy and IronPython.
The simple explanation of the algorithm is like this: 1. Choose a set of faces, for example ten faces, which are close to the point you want to measure the distance; 2. Measure the distance of the point to the each choose triangle (mesh face). To choose a set of close faces, unfortunately I have only a Matlab code, feel free to ask if you want. It works like this: 1. Measure the distance of your point to each point of a mesh: distance = dot_product(mesh_vertex-point, mesh_vertex-point); 2. Pick the 10* closest points; 3. Pick the faces of those 10* closest points; * You can pick 10 or any number of points you want, if you mesh is more like a flat plane only a couple of points is enough. Now you have the set of candidate faces. Measure the distance between your point and each of candidate faces. I do it based on Gwendolyn Fischer (MathWorks) and David Eberly, 'Distance Between Point and Triangle in 3D', Geometric Tools, LLC, (1999) http:\\ www.geometrictools.com/Documentation/DistancePoint3Triangle3.pdf. I have coded in Python. It's here https://dl.dropboxusercontent.com/u/6082839/face_distance.py The code uses 1. self._v is a set of 3d points like this [[v1x, v1y, v1z], [v2x, v2y, v2z], [v3x, v3y, v3z], ...]; 2. face is a set of the face indexes, for example face 1 has vertexes [1 2 3]; 3. The vec class, which deals with vector operations. I have done that for 30 000 faces mesh in few seconds. I hope you can understand and use the codes, feel free to ask about it. Good luck Lie Pablo On 8 August 2013 05:09, Uwe Schlifkowitz <schlifkow...@intales.com> wrote: > Hi Charles, > > I'm not sure what you mean by segments? But I am interested in an example! > > The leak is indeed in BrepExtrema_DistShapeShape. > My current approach is to calculate a midpoint for each of the blue > edges, which is fast even for 6000 edges. Then I use > scipy.spatial.KDTree for a nearest neighbour search. > In cases where two or more edges are found, I still use > BRepExtrema_DistShapeShape to select the edge closest to that node. > > > https://dl.dropboxusercontent.com/u/32772/pythonOCC/findverticesnearedge.png > > Uwe > > On 07/08/13 06:44, Charles Sharman wrote: > > Hi Uwe, > > > > Are your edges segments? It seemed like they might be from the > edgeScaling > > and edgeDirection lines. If so, there are closed-form methods you could > use > > with numpy to calculate this very, very fast. (Just dig up an old > parametric > > calculus book.) I can write a quick example for you if this is indeed > the > > case. > > > > If not, BrepExtrema_DistShapeShape looked like a good choice to me. > (I'm not > > aware of alternatives.) Have you profiled your program to find where the > > time and memory sink occurs? Is it in the BrepExtrema_DistShapeShape > routine > > or the math at the bottom? I would assume it's in > > BRepExtrema_DistShapeShape. If so, since your edges are short, couldn't > you > > prefilter many of the edges out before BrepExtrema_DistShapeShape is > called > > by putting a bounding box around the edge and see if the bounding box > points > > are close to the vertex with numpy? > > > > - Charles > > > > > > > > > > _______________________________________________ > > Pythonocc-users mailing list > > Pythonocc-users@gna.org > > https://mail.gna.org/listinfo/pythonocc-users > > > > -- > INTALES GmbH Engineering Solutions > Uwe Schlifkowitz -- Software Engineer > Innsbrucker Str. 1, A-6161 Natters > Phone: +43 512 54611120 -- schlifkow...@intales.com > > _______________________________________________ > Pythonocc-users mailing list > Pythonocc-users@gna.org > https://mail.gna.org/listinfo/pythonocc-users >
_______________________________________________ Pythonocc-users mailing list Pythonocc-users@gna.org https://mail.gna.org/listinfo/pythonocc-users