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

    Intersecting line with BoundingBox

    Scheduled Pinned Locked Moved Developers' Forum
    10 Posts 3 Posters 351 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.
    • A Offline
      Aerilius
      last edited by

      The Geom module helps us to intersect lines with lines, lines with planes, planes with planes.

      Has anyone needed to cast rays into bounding boxes? I would prefer using API methods before implementing something on my own.
      It seems SketchUp gives us only raytests for testing against DrawingElements, but not for pure geometry.

      1 Reply Last reply Reply Quote 0
      • Chris FullmerC Offline
        Chris Fullmer
        last edited by

        I think you just have to define the planes of the bounding box and use those planes. Will that work?

        Lately you've been tan, suspicious for the winter.
        All my Plugins I've written

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

          The intersection, which will be at the edge of the bounding box, will be considered inside?
          No accuracy issues?

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

          1 Reply Last reply Reply Quote 0
          • Chris FullmerC Offline
            Chris Fullmer
            last edited by

            You'll also have to watch out for a line that goes through a corner of the box, but not the corner there the planes have been setup. That will in fact intersect your bounding box, but won't show up as an intersection unless you define all 6 planes.

            Lately you've been tan, suspicious for the winter.
            All my Plugins I've written

            1 Reply Last reply Reply Quote 0
            • A Offline
              Aerilius
              last edited by

              As for what I tested, points on the sides of the bounding box are considered inside ( BoundingBox.contains? is true).

              I believe it should work with 3 instead of 6 planes, since the planes are infinite (bigger than the sides of the box).
              An infinite straight line must intersect with any 3 orthogonal planes. If the line is a ray (half infinite), there is the case that it does not intersect the planes if it points away from the plane's intersection. In that case the line either starts in the box or it is completely outside.

              1 Reply Last reply Reply Quote 0
              • Chris FullmerC Offline
                Chris Fullmer
                last edited by

                Maybe this condition isn't a problem for your script, but here is a case where a line starts outside the bounding box, intersects the bounding box, but would return false if you only test it against 3 planes of the bounding box. (hopefully that graphic makes some sense πŸ˜• )


                box.jpg

                Lately you've been tan, suspicious for the winter.
                All my Plugins I've written

                1 Reply Last reply Reply Quote 0
                • A Offline
                  Aerilius
                  last edited by

                  Ah, yes, you are right. I get an intersection with the plane on the left, but the intersection point is not in the bounding box.

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

                    Chris got his thinking hat on! πŸ‘

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

                    1 Reply Last reply Reply Quote 0
                    • Chris FullmerC Offline
                      Chris Fullmer
                      last edited by

                      Yes sir! My new hat makes me feel very smart (and slightly Norwegian!).

                      Lately you've been tan, suspicious for the winter.
                      All my Plugins I've written

                      1 Reply Last reply Reply Quote 0
                      • A Offline
                        Aerilius
                        last edited by

                        I hadn't considered that because planes are infinite, but it works well combined with BoundingBox.contains?

                        
                        def intersect_line_boundingbox(line, bb)
                          # Intersect with 6 planes of the bounding box's sides.
                          p0 = bb.corner(0)
                          p1 = bb.corner(7)
                          [ [p0, X_AXIS],
                            [p0, Y_AXIS],
                            [p0, Z_AXIS],
                            [p1, X_AXIS],
                            [p1, Y_AXIS],
                            [p1, Z_AXIS]
                          ].each{|plane|
                            intersection = Geom;;intersect_line_plane(line, plane)
                            # Stop when the intersection point is inside the bounding box.
                            return intersection if bb.contains?(intersection)
                            # else continue
                          }
                          # No intersection (because bb is aside line or behind line start).
                          return nil
                        end
                        

                        There is certainly room for optimization (ie. maybe less than 6 planes, or checking whether BB is behind line start).
                        I first had the code with an infinite straight line (starting from -infinity) and only one intersection with a plane but that failed due to precision errors.

                        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