@pascal,
I am developing a Python script to trim a mesh in cases where Rhino’s Mesh trim fails. As part of this, a closed boundary curve is projected onto a mesh which creates points everywhere the line crosses the edge of a mesh face. ClosestPoint is used to find which mesh face the point falls on and then the distance from the point to each face edge is found to select the closest edge. But the shocking thing I discovered is that if I used the EdgeLine method to get lines representing the 3 edges, then the measured distances are about a million times less accurate than using the 3 vertices of a face to make 3 edge lines from scratch. Below is shown the portion of the script where I compare these two approaches:
# Use vertices of face to make edge lines for the face.
i2,i3,i1,ix = faces[f_index]; p1,p2,p3 = vertices[i1],vertices[i2],vertices[i3]
# Make lines for edges of face from vertices.
l1,l2,l3 = Line(p1,p2),Line(p2,p3),Line(p3,p1)
# Find distance from boundary point pt to edge lines.
d1p,d2p,d3p = l1.DistanceTo(pt,True),l2.DistanceTo(pt,True),l3.DistanceTo(pt,True)
# This gives very accurate results.
print 'Vertices: face {0} Distances = {1:.4e}, {2:.4e}, {3:.4e}'.format(f_index,d1p,d2p,d3p)
# Use EdgeLine to make edge lines of face.
e1,e2,e3 = edges.GetEdgesForFace(f_index)
# Get edge line of edges.
l1,l2,l3 = edges.EdgeLine(e1),edges.EdgeLine(e2),edges.EdgeLine(e3)
# Find distance from boundary point pt to edge lines.
d1p,d2p,d3p = l1.DistanceTo(pt,True),l2.DistanceTo(pt,True),l3.DistanceTo(pt,True)
# This is a million times less accurate.
print 'EdgeLines: face {0} Distances = {1:.4e}, {2:.4e}, {3:.4e}\n'.format(f_index,d1p,d2p,d3p)
If you run the attached Python script on the attached .3dm file, you will see a printout of the distances from each boundary point to the 3 edges of the mesh face it crosses calculated in 2 ways (1) First with the lines for the edges of the face constructed using the mesh vertices and (2) using EdgeLine to create a line for each edge. On each printout line (a few are shown below), the distance to the closest edge is very small, around 1e-14 when using vertice-created lines and around 1e-6 when using EdgeLine-created lines. Changing the document Absolute tolerance made no difference in this result.
Vertices: face 1720 Distances = 8.8818e-16, 1.7747e-01, 6.7850e-02
EdgeLines: face 1720 Distances = 1.8368e-06, 1.7747e-01, 6.7850e-02
Vertices: face 1719 Distances = 1.4222e-01, 1.4211e-14, 2.1637e-01
EdgeLines: face 1719 Distances = 1.4222e-01, 8.2492e-07, 2.1637e-01
One could say both are small so why worry? But for large meshes with 10M faces, I had been getting many failures in identifying the correct edge using EdgeLine. Now that I have switched to using vertice-created lines, all these failures are gone. This has provided a major improvement in the robustness of my mesh trimming script.
Is it reasonable that these two methods should give a million times different result?
EdgeLinePoor.py (10.3 KB)
TinyMeshEdgeLinePoor.3dm (341.4 KB)