sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Vector3d.samedirection? tolerance is not what is expected

    Scheduled Pinned Locked Moved Developers' Forum
    4 Posts 3 Posters 200 Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • thomthomT Offline
      thomthom
      last edited by

      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 coplanar

      Problem
      Using Vector3d.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 (and parallel? etc. etc.) to be identical with the behaviour in SU.

      Thomas Thomassen — SketchUp Monkey & Coding addict
      List of my plugins and link to the CookieWare fund

      1 Reply Last reply Reply Quote 0
      • RunnerPackR Offline
        RunnerPack
        last edited by

        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:

        1. Generate a pair of faces joined at angle "theta", which is initially 0 radians.

        2. Delete the common Edge.

        3. 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.

        4. Increment theta by some small amount (0.001 radians, or something).

        5. 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.

        You might have noticed... I'm a bit of a ferpectionist.

        1 Reply Last reply Reply Quote 0
        • TIGT Offline
          TIG Moderator
          last edited by

          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

          1 Reply Last reply Reply Quote 0
          • thomthomT Offline
            thomthom
            last edited by

            @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.

            Thomas Thomassen — SketchUp Monkey & Coding addict
            List of my plugins and link to the CookieWare fund

            1 Reply Last reply Reply Quote 0
            • 1 / 1
            • First post
              Last post
            Buy SketchPlus
            Buy SUbD
            Buy WrapR
            Buy eBook
            Buy Modelur
            Buy Vertex Tools
            Buy SketchCuisine
            Buy FormFonts

            Advertisement