sketchucation logo sketchucation
    • Login
    🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    BoundingBox.intersect

    Scheduled Pinned Locked Moved Developers' Forum
    10 Posts 5 Posters 1.2k Views 5 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.
    • DavidBoulderD Offline
      DavidBoulder
      last edited by

      Has anyone had problems with this. This is my first time using it, and I'm using it in conjunction with valid? to see if there are any points.

      What I've found is that if my two groups (in this case cubes) don't share any X-axis limits, then it correctly identifies if the objects touch or not. If however they have overlapping X-axis limits, it always returns "true" for BoundingBox.intersect.valid? even if the Y-axis and Z-axis limits don't overlap at all. If any of the three axes don't overlap the valid? should return "false" Below I took the code from the API sample and adjusted it to show two parallel lines that are running along the Y and then the X axis. They should both return false, but the pair along the X axis returns true.

      Any thoughts on this?

      Error 404 (Not Found)!!1

      favicon

      (code.google.com)

       boundingbox1 = Geom;;BoundingBox.new
       boundingbox1.add [0,0,0]
       boundingbox1.add [0,100,0]
       boundingbox2 = Geom;;BoundingBox.new
       boundingbox2.add [100,0,0]
       boundingbox2.add [100,100,0]
       boundingboxA = boundingbox1.intersect boundingbox2
       puts boundingboxA.valid?
      
       boundingbox3 = Geom;;BoundingBox.new
       boundingbox3.add [0,0,0]
       boundingbox3.add [100,0,0]
       boundingbox4 = Geom;;BoundingBox.new
       boundingbox4.add [0,100,0]
       boundingbox4.add [100,100,0]
       boundingboxB = boundingbox3.intersect boundingbox4
       puts boundingboxB.valid?
      

      boundingboxA.valid? correctly returns "false"
      boundingboxB.valid? incorrectly returns "true"

      FYI - I have attached a screenshots of a simple example using two cubes where one returns true and the other false. Code above is similar but just two lines, vs. two boxes.

      ![This correctly shows boundingbox.intersect? as "false"](/uploads/imported_attachments/EJqD_intersectreturnsfalse.png "This correctly shows boundingbox.intersect? as "false"")
      ![This incorrectly shows boundingbox.intersect? as "true"](/uploads/imported_attachments/psx5_intersectreturnstrue.png "This incorrectly shows boundingbox.intersect? as "true"")

      Just a short followup. If I add the following code to each pair of lines here are the results

      
       puts boundingboxA.diagonal
       puts boundingboxA.height
       puts boundingboxA.depth
       puts boundingboxA.width
       puts boundingboxA.corner (0)
       puts boundingboxA.corner (1)
       puts boundingboxA.corner (2)
       puts boundingboxA.corner (3)
       puts boundingboxA.corner (4)
       puts boundingboxA.corner (5)
       puts boundingboxA.corner (6)
       puts boundingboxA.corner (7)
      
      

      8' 4"
      8' 4"
      0"
      0"
      (1000000000000000000000000000000", 0", 0")
      (-1000000000000000000000000000000", 0", 0")
      (1000000000000000000000000000000", 100", 0")
      (-1000000000000000000000000000000", 100", 0")
      (1000000000000000000000000000000", 0", 0")
      (-1000000000000000000000000000000", 0", 0")
      (1000000000000000000000000000000", 100", 0")
      (-1000000000000000000000000000000", 100", 0")
      false
      8' 4"
      0"
      0"
      8' 4"
      (1000000000000000000000000000000", 0", 0")
      (100", 1000000000000000000000000000000", 0")
      (0", -1000000000000000000000000000000", 0")
      (100", -1000000000000000000000000000000", 0")
      (0", 1000000000000000000000000000000", 0")
      (100", 1000000000000000000000000000000", 0")
      (0", -1000000000000000000000000000000", 0")
      (100", -1000000000000000000000000000000", 0")
      true
      ""

      --

      David Goldwasser
      OpenStudio Developer
      National Renewable Energy Laboratory

      1 Reply Last reply Reply Quote 0
      • J Offline
        Jim
        last edited by

        @unknownuser said:

        (1000000000000000000000000000000", 0", 0")

        Seems like a long way from home. I would have thought the bb to be around the ORIGIN.

        I've never used the .intersect method - never realized it existed until now, actually.

        Hi

        1 Reply Last reply Reply Quote 0
        • DavidBoulderD Offline
          DavidBoulder
          last edited by

          I thought it was a long way from home as well. I thought it would be an empty bounding box without any points, so I didn't know what I expected corner 0 to return, I thought maybe "nil"

          By the way, here is what I get for points on a new empty bounding box.

          boundbox = Geom;;BoundingBox.new
          puts boundbox.height
          puts boundbox.width
          puts boundbox.depth
          puts boundbox.corner 0
          puts boundbox.corner 1
          puts boundbox.corner 2
          puts boundbox.corner 3
          puts boundbox.corner 4
          puts boundbox.corner 5
          puts boundbox.corner 6
          puts boundbox.corner 7
          boundbox.valid?
          

          Height, Depth, and Width return 0 (instead of the 8'4" that came up on my earlier example), but still large number for point coordinates. The 8'4" is the 100 inches, but I don't know how that ever got to be the height in the earlier example.

          0"
          0"
          0"
          (1000000000000000000000000000000", 1000000000000000000000000000000", 1000000000000000000000000000000")
          (-1000000000000000000000000000000", 1000000000000000000000000000000", 1000000000000000000000000000000")
          (1000000000000000000000000000000", -1000000000000000000000000000000", 1000000000000000000000000000000")
          (-1000000000000000000000000000000", -1000000000000000000000000000000", 1000000000000000000000000000000")
          (1000000000000000000000000000000", 1000000000000000000000000000000", -1000000000000000000000000000000")
          (-1000000000000000000000000000000", 1000000000000000000000000000000", -1000000000000000000000000000000")
          (1000000000000000000000000000000", -1000000000000000000000000000000", -1000000000000000000000000000000")
          (-1000000000000000000000000000000", -1000000000000000000000000000000", -1000000000000000000000000000000")
          "false"

          --

          David Goldwasser
          OpenStudio Developer
          National Renewable Energy Laboratory

          1 Reply Last reply Reply Quote 0
          • J Offline
            Jim
            last edited by

            I can only guess, but do the large numbers mean infinite overlap in that dimension because that dimension has 0 length? (Or something like that.)

            Hi

            1 Reply Last reply Reply Quote 0
            • AdamBA Offline
              AdamB
              last edited by

              Are you using SU6? I seem to remember the intersect is broken in SU6.

              Developer of LightUp Click for website

              1 Reply Last reply Reply Quote 0
              • DavidBoulderD Offline
                DavidBoulder
                last edited by

                Nope, I'm using current version of 7.1 on PC, I haven't tried on my mac PC at home.

                --

                David Goldwasser
                OpenStudio Developer
                National Renewable Energy Laboratory

                1 Reply Last reply Reply Quote 0
                • DavidBoulderD Offline
                  DavidBoulder
                  last edited by

                  So if this is a bug here is my workaround may be to create similar results by using min and max points for the two bounding boxes being intersected. For my use I just need to know if they intersect, not what that resulting bounding box is.

                  This isn't code, just outline of what I'm thinking

                  Get min max for bounding box a and b
                  min a
                  max a
                  min b
                  max b

                  if
                  min ax < min bx < max ax or min ax < max bx < max ax
                  and
                  min ay < min by < max ay or min ay < max by < max ay
                  and
                  min az < min bz < max az or min az < max bz < max az

                   then bounding boxes intersect
                  

                  else
                  they don’t intersect

                  --

                  David Goldwasser
                  OpenStudio Developer
                  National Renewable Energy Laboratory

                  1 Reply Last reply Reply Quote 0
                  • K Offline
                    kyyu
                    last edited by

                    I used bounding box intersection in my Slots 4 Tabs plugin. How about using volume to see if they intersect?

                    b1 = sel[0].bounds
                    b2 = sel[1].bounds
                    bb = b1.intersect b2
                    puts bb.valid?
                    puts bb.width * bb.height * bb.depth

                    1 Reply Last reply Reply Quote 0
                    • J Offline
                      Jim
                      last edited by

                      I see the same problem. It does seem like a clear bug. Align the boxes along each of the 3 axes, test for valid BB.intersect, and 2 of 3 alignments return valid, while the 3rd (along X) returns not valid.

                      Hi

                      1 Reply Last reply Reply Quote 0
                      • P Offline
                        PurpLev
                        last edited by

                        I'm seeing the same problem, tested on both Mac and PC with SU 7.1.6

                        this is clearly a bug as the function does not do what it's name represents. although this would be renamed and used to find if 2 bounding boxes are within the same projected space.

                        I recently posted pretty much the same post here:

                        http://forums.sketchucation.com/viewtopic.php?f=180&t=29156

                        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