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

    Intersect_line_line question

    Scheduled Pinned Locked Moved Developers' Forum
    8 Posts 3 Posters 312 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.
    • s_k_e_t_c_h_yS Offline
      s_k_e_t_c_h_y
      last edited by

      Hi,
      I'm having trouble with Geom.intersect_line_line not giving the expected results so I was hoping someone could either tell me what I'm doing wrong or that the function is bugged so I know whether to rewrite it.

      According to the documentation in the API

      @unknownuser said:

      Geom.intersect_line_lineSketchUp 6.0+
      The intersect_line_line computes the intersection of two lines.

      Arguments:

      line1
      The first line to intersect.
      line2
      The second line to intersect.
      Returns:

      point
      The intersection point. Returns nil if they do not intersect.
      line1 = [Geom::Point3d.new(10,0,0), Geom::Vector3d.new(1,0,0)]
      line2 = [Geom::Point3d.new(0,10,0), Geom::Point3d.new(20,10,0)]
      pt = Geom.intersect_line_line(line1, line2)

      This will return the point (10,10,0).

      If you type in their example into the Ruby editor it doesn't actually work as advertised, it returns nil.

      Here is an example of two parallel lines returning a value...

      l1 = [[0,0,0], [10,0,0]]
      [[0, 0, 0], [10, 0, 0]]
      l2 = [[0,5,0], [10,5,0]]
      [[0, 5, 0], [10, 5, 0]]
      i = Geom.intersect_line_line(l1, l2)
      Point3d(-10, 0, 0)
      

      Thoughts?

      Sincerely, Paul.

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

        @s_k_e_t_c_h_y said:

        If you type in their example into the Ruby editor it doesn't actually work as advertised, it returns nil.

        Yes there are many errors in the API dictionary.

        The code example has the wrong vector argument for line1, and the example should read:

         line1 = [Geom;;Point3d.new(10,0,0), Geom;;Vector3d.new(0,1,0)]
         line2 = [Geom;;Point3d.new(0,10,0), Geom;;Point3d.new(20,10,0)]
         pt = Geom.intersect_line_line(line1, line2)
         # This will return the point (10,10,0).
         
         line3 = [Geom;;Point3d.new(10,0,0), Geom;;Vector3d.new(1,0,0)]
         pt2 = Geom.intersect_line_line(line2, line3)
         # This will return nil, as the lines are parallel to each other.
        
        

        🤓

        I'm not here much anymore.

        1 Reply Last reply Reply Quote 0
        • s_k_e_t_c_h_yS Offline
          s_k_e_t_c_h_y
          last edited by

          Thanks Dan,
          That makes sense. I see that the way the function operates however isn't what I was after. The function as it stands turns the lines into infinite rays defined by the line's two points and then checks if the infinite rays intersect. I just want to check if the line segments bounded by the pairs of points intersect.

          I'm muddling through implementing this now, unless you know of an existing coded examples. There are 5 cases to check for
          
          1. Parallel Lines
          2. Normal Intersection within line segments
          3. Intersection, but outside limits defined by line segment points
          4. No intersection at all
          5. Lines are coincident (intersection is a line, not a point)

          Sincerely, Paul.

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

            @s_k_e_t_c_h_y said:

            The function as it stands turns the lines into infinite rays defined by the line's two points and ...

            In SketchUp lines are infinite, ... edges are not.

            You might try using bounding boxes around your "segemnts"...
            see API Geom::BoundingBox#intersect()

            💭

            I'm not here much anymore.

            1 Reply Last reply Reply Quote 0
            • s_k_e_t_c_h_yS Offline
              s_k_e_t_c_h_y
              last edited by

              Thanks again Dan,
              I'll see what I can come up with =).

              1 Reply Last reply Reply Quote 0
              • s_k_e_t_c_h_yS Offline
                s_k_e_t_c_h_y
                last edited by

                Not the most mathematically efficient I think, but this will do for now...

                Redirecting to Google Groups

                favicon

                (groups.google.com)

                1 Reply Last reply Reply Quote 0
                • S Offline
                  slbaumgartner
                  last edited by

                  If you have two points p1 = [x1,y1,z1] and p2 = [x2,y2,z2] the line passing through them is given by

                  [x,y,z] = p1 + k(p2-p1)

                  The segment of the line between the two points is for 0.0 <=k <= 1.0

                  So, if intersect_line_line returns a point (meaning that your two lines intersected), you just have to test that the intersection point satisfies the equation above for a k in the allowed range. It will necessarily be the same k for x, y, and z.

                  1 Reply Last reply Reply Quote 0
                  • s_k_e_t_c_h_yS Offline
                    s_k_e_t_c_h_y
                    last edited by

                    Ah,
                    Good point sl. I used a similar test for a line-plane intersection test.

                    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