Vector3d.samedirection? tolerance is not what is expected
-
Simple scenario:
Iterate over all the edges in the selection,
if the edge has two faces attached: compare them and see if they are coplanar
erase edge if faces are coplanarProblem
UsingVector3d.samedirection?
to check if they are coplanar fails in certain cases where faces are nearly co-planar, but not quite. It will return true to normals where when you erase the edge the face disappear.
I would have expected.samedirection
to only return true for normals that where only so close that SU join the faces if the edge between them are erased.A workaround is:
if face[0].normal % face[1].normal == 1.0
But that is too strict. That would leave edges which is possible to delete.
Instead I have to guess the precision of SU when it joins faces and when it doesn’t.What I’d like is for the tolerance of
.samedirection
(andparallel?
etc. etc.) to be identical with the behaviour in SU. -
You probably already came up with this, but here's my idea of a method to find SU's tolerance:
Start with a blank model.
Start a loop:
-
Generate a pair of faces joined at angle "theta", which is initially 0 radians.
-
Delete the common Edge.
-
If there is one Face in SU.model.entities, repeat. If there are zero, stop because theta is larger than SU's tolerance for coplanar Faces.
-
Increment theta by some small amount (0.001 radians, or something).
-
Clear the model and loop.
You can repeat the test with theta closer to the cutoff and incrementing by smaller amounts to converge on the precise value.
I wish I had time to do this (I probably shouldn't have taken the time to post this ) so, I hope you do it, 'cause I'd like to know what you find out.
-
-
For deleting coplanar edges I successfully use
if e.faces[0].normal.dot(e.faces[1].normal) > 0.99999999 && e.faces[0].material==e.faces[1].material && e.faces[0].back_material==e.faces[1].back_material
This avoids the problem of erasing edges that remove the face as the normals aren't quite == -
@tig said:
For deleting coplanar edges I successfully use
if e.faces[0].normal.dot(e.faces[1].normal) > 0.99999999 && e.faces[0].material==e.faces[1].material && e.faces[0].back_material==e.faces[1].back_material
This avoids the problem of erasing edges that remove the face as the normals aren't quite ==I've been using nearly the same: (after some testing I came down to: 0.9999999991)
But the problem is that there seem to be a range of dot products of edges that can be removed and those that can't overlaps.
http://forums.sketchucation.com/viewtopic.php?f=180&t=22920&start=0#p193613
I could set the precision to a safe value - but that'd leave edges that still could be deleted.
Advertisement