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

    BoundindBox intersect problem

    Scheduled Pinned Locked Moved Developers' Forum
    12 Posts 4 Posters 222 Views 4 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.
    • Didier BurD Offline
      Didier Bur
      last edited by

      Hi all,

      Here's my problem:
      I have to detect if 2 component instances (or their bounding boxes) of buildings intersect.
      Below is the code of the method that does it, in the class Sketchup::ComponentInstance:

      
      class Sketchup;;ComponentInstance
      def intersectBuildings(obj)
          return !self.bounds.intersect(obj.bounds).empty?
      end
      
      

      The problem is that when the 2 buildings don't intersect, the method always return true instead of false, and below is an example of such a bounding box object corners:

      (76.436968m,  25399999999999994000000000000m, 0.234637m)
      (85.21837m,  25399999999999994000000000000m, 0.234637m)
      (76.436968m,  -25399999999999994000000000000m, 0.234637m)
      (85.21837m,  -25399999999999994000000000000m, 0.234637m)
      (76.436968m,  25399999999999994000000000000m, 7.018104m)
      (85.21837m,  25399999999999994000000000000m, 7.018104m)
      (76.436968m,  -25399999999999994000000000000m, 7.018104m)
      (85.21837m,  -25399999999999994000000000000m, 7.018104m)
      

      Y value seems to be infinite. Anyone encountered this before me ? I've not notice any answer on this subbject in this forum 😒

      Thanks in advance,

      DB

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

        I do think I've seen threads on the topic.

        This appear to be a similar issue:
        http://forums.sketchucation.com/viewtopic.php?f=180&t=28709

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

        1 Reply Last reply Reply Quote 0
        • Didier BurD Offline
          Didier Bur
          last edited by

          Thanks TT,
          I wonder why I didn't see this topic, incorrect search keywords maybe...

          DB

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

            I used google instead of the forum search. Often does a better job.

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

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

              @didier bur said:

              I have to detect if 2 component instances (or their bounding boxes) of buildings intersect.

              Are the building components manifold solids ??

              If so you can use my intersect_with?() method, as is:
              [ Code ] intersect_with?() Group test method

              If not, perhaps you can create two temporary manifold solids (using the bounding box vertices of the components,) then feed my intersect_with?() method, those temporary solids. After you get the boolean result, you can undo the operation (that created the temporary solids,) or just abort the operation.

              I'm not here much anymore.

              1 Reply Last reply Reply Quote 0
              • Didier BurD Offline
                Didier Bur
                last edited by

                Thanks Dan,
                The components are manifold solids.
                I'll check your intersect_with? method asap and let you know.

                DB

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

                  You could also use this - it doesn't need manifold solids...
                  tr=Geom::Transformation.new() tgp=entities.add_group() inst=obj1.entities.intersect_with(true,tr,tgp.entities,tr,false,obj2) tgp.erase! return true if inst[0] return nil
                  You might need to mess around with the 'transformations' if the 2 objects aren't in the same context ?

                  TIG

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

                    Hmmm.. the API doctionary says that entities.intersect_with() returns nil

                    Does it really return the new intersect edges ?? New faces ??

                    And if the objects are NOT in the same context.. would this method even intersect ?

                    I'm not here much anymore.

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

                      @dan rathbun said:

                      Hmmm.. the API doctionary says that entities.intersect_with() returns nil
                      Does it really return the new intersect edges ?? New faces ??
                      And if the objects are NOT in the same context.. would this method even intersect ?
                      The API is [as ever!] completely wrong - the method returns an array of all of the intersected results [edges typically, when put into a separate container as here] - just try it and see...
                      If the two intersecting objects are in different contexts you must adjust the transformations to reflect this - it can be done - I do it in 'Honeycomber'...

                      TIG

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

                        IT's so crazy.. I never noticed the Entities.intersect_with() method before.

                        At first blush, it seems a strange place to have it as an instance method of the Entities collection, (being why I did not notice it,) but when you think about it.. that's the correct place for it, so that the model's context can benefit as well. (The alternative would have been to define it 3 times, in Model, Group and Component.)

                        I did notice a weird thing. If the groups do not intersect.. the temporary group is empty, and sometimes Sketchup deletes it. I did not expect this. I was trying to reuse the empty group reference for another intersect.. and got the ol' "reference to Deleted Entity" error.

                        I can see advantages to using this method rather than a boolean trim, as no undo would be needed. ( and might be faster.)

                        I'm not here much anymore.

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

                          An empty temporary group will not survive long if you do other things, so create it just before you use it...

                          TIG

                          1 Reply Last reply Reply Quote 0
                          • Didier BurD Offline
                            Didier Bur
                            last edited by

                            Hi guys,
                            Thanks for all these comments.
                            What I'have done finally is the following:

                            • Made a hash with all my buildings and their local bounding boxes,
                            • Iterated through this hash and test all other bounding box points of other buildings,
                            • skiped all bounding boxes that are way too far to intersect with the considered building,
                            • coded a method to test if a 3dPoint is in a set of 8 points (a bounding box).
                              This is a very fast and efficient process (about 200 buildings collisions (with all 199 others) tested in 0.5 second)

                            Regards,

                            DB

                            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