sketchucation logo sketchucation
    • Login
    πŸ€‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Closest face problem

    Scheduled Pinned Locked Moved Developers' Forum
    5 Posts 3 Posters 592 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.
    • hsmyersH Offline
      hsmyers
      last edited by

      Imagine two selected objects. I'd like to determine the closest pairing of one face from each. I'll be using the faces from the bounding box of each object. My goal is to move one from the BB center to it's opposing BB center, but that is later and I've cobbled code to do so. What I'm currently doing is a distance from CP to origin and then comparing the two. It works some times and fails the rest of the time. This may be influenced by a second problem and that has to do with selection. How do I reliably tell first selection from second? Currently it's the simple minded @sel[0] and @sel[1] as first and second where @sel decends from Sketchup.active_mode.entities.selection.

      In sum, I'd like to know how to:

      • Determine closest pair of faces from two object bounding boxes?* Determine order of selections

      Will bake cookies!! πŸ˜‰

      1 Reply Last reply Reply Quote 0
      • Dan RathbunD Offline
        Dan Rathbun
        last edited by

        @hsmyers said:

        I'll be using the faces from the bounding box of each object.

        Bounding Boxes are virtual geometric "helper" objects that do not have faces.

        @hsmyers said:

        How do I reliably tell first selection from second? Currently it's the simple minded @sel[0] and @sel[1] as first and second where @sel results from Sketchup.active_model.entities.selection.

        You will need to implement a [%(#BF0000)[SelectionObserver]](http://www.sketchup.com/intl/en/developer/docs/ourdoc/selectionobserver) subclass.

        I'm not here much anymore.

        1 Reply Last reply Reply Quote 0
        • hsmyersH Offline
          hsmyers
          last edited by

          @dan rathbun said:

          @hsmyers said:

          I'll be using the faces from the bounding box of each object.

          Bounding Boxes are virtual geometric "helper" objects that do not have faces.

          True but it is easy enough to construct the necessary 'face' and then derive the center. I should have been more clear. Hmmmm...that said, how about closest pair of points? A sorted list of 64 lengths? Or is the something less sledgehammerish?

          @unknownuser said:

          @hsmyers said:

          How do I reliably tell first selection from second? Currently it's the simple minded @sel[0] and @sel[1] as first and second where @sel results from Sketchup.active_model.entities.selection.

          You will need to implement a [%(#BF0000)[SelectionObserver]](http://www.sketchup.com/intl/en/developer/docs/ourdoc/selectionobserver) subclass.

          Ah! A little bit deeper into the tool pool...splash!! Thanks for the tip and the correction πŸ˜„ Any ideas on the revised question?

          1 Reply Last reply Reply Quote 0
          • sdmitchS Offline
            sdmitch
            last edited by

            @hsmyers said:

            how about closest pair of points?

            Since you are only dealing with two objects, it shouldn't matter which is sel[0] or sel[1]

            To find the closest corners of two objects

            mod = Sketchup.active_model
            ent = mod.active_entities
            sel = mod.selection
            vue = mod.active_view
            obj0 = sel[0]; obj1 = sel[1]; cor0=[]; cor1=[]
            [0,1,2,3,4,5,6,7].each{|i| cor0<<obj0.bounds.corner(i)}
            [0,1,2,3,4,5,6,7].each{|i| cor1<<obj1.bounds.corner(i)}
            md=1e9;m=n=0
            cor0.each_with_index{|c0,i|
             cor1.each_with_index{|c1,j|
              d = c0.distance(c1)
              if d < md
               md=d;m=i;n=j
              end
             }
            }
            UI.messagebox "Obj0 Cor#{m} to Obj1 Cor#{n} is #{Sketchup.format_length(md)}"
            
            

            Nothing is worthless, it can always be used as a bad example.

            http://sdmitch.blogspot.com/

            1 Reply Last reply Reply Quote 0
            • hsmyersH Offline
              hsmyers
              last edited by

              @sdmitch said:

              @hsmyers said:

              how about closest pair of points?

              Since you are only dealing with two objects, it shouldn't matter which is sel[0] or sel[1]

              To find the closest corners of two objects

              mod = Sketchup.active_model
              > .
              > .
              > .
              > UI.messagebox "Obj0 Cor#{m} to Obj1 Cor#{n} is #{Sketchup.format_length(md)}"
              > 
              

              Thank you for the snippet!

              You are correct excepting that the tool in question will move one of the two objects such that the opposing face centers are touching plus or minus an offset. Sorry for the grossly incomplete spec 😞 My plan (very fluid and quite murky ) is take the first selection as the moving object and the second as the fixed object. I've some notion about non-parallel faces requiring ( optionally ) an rotational adjustment. However it's my goal to keep things as simple as possible. My usage is to stack components together to assemble the model much like one would in actuality. Hex nuts, lock washer on threaded rod etc.

              Additionally, there is the self-educational aspect of solving the which selection is on first πŸ˜„ This tool already has four options and looks to acquire one or more in the future. So it seems prudent to solve this now to make ready for the unforeseen. 'Sides any excuse to cut code!!

              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