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

    Error Drawing Lines

    Scheduled Pinned Locked Moved Developers' Forum
    8 Posts 5 Posters 549 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.
    • ppoublanP Offline
      ppoublan
      last edited by

      Dear all,
      I'm facing an issue I can't understand.
      These two codes should produce the same result.

      Here is the code that does not draw the correct lines :
      (no line is drawn from pt2 to pt1 and this line is replaced by one joining pt3, pt1)

      pt1 = Geom::Point3d.new(0.98787,0.926013,0)
      pt2 = Geom::Point3d.new(0.988135,0.925025,0)
      pt3 = Geom::Point3d.new(0.977696,0.924673,0)
      Sketchup.active_model.entities.add_line(pt3,pt2)
      Sketchup.active_model.entities.add_line(pt2,pt1)

      And what I got when running it in the console
      error.JPG

      If I reverse the order lines are drawing, I got the correct result.

      pt1 = Geom::Point3d.new(0.98787,0.926013,0)
      pt2 = Geom::Point3d.new(0.988135,0.925025,0)
      pt3 = Geom::Point3d.new(0.977696,0.924673,0)
      Sketchup.active_model.entities.add_line(pt1,pt2)
      Sketchup.active_model.entities.add_line(pt2,pt3)
      correct.jpg

      I was thinking of something linked to the precision of SU but cant explain if its the limit why the one code produces the correct result and the other not.

      Any idea appreciated.
      Yours
      Pascal

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

        @ppoublan said:

        Dear all,
        I'm facing an issue I can't understand.
        These two codes should produce the same result.

        Here is the code that does not draw the correct lines :
        (no line is drawn from pt2 to pt1 and this line is replaced by one joining pt3, pt1)

        pt1 = Geom::Point3d.new(0.98787,0.926013,0)
        pt2 = Geom::Point3d.new(0.988135,0.925025,0)
        pt3 = Geom::Point3d.new(0.977696,0.924673,0)
        Sketchup.active_model.entities.add_line(pt3,pt2)
        Sketchup.active_model.entities.add_line(pt2,pt1)

        And what I got when running it in the console
        [attachment=1:24mkndsa]<!-- ia1 -->error.JPG<!-- ia1 -->[/attachment:24mkndsa]

        If I reverse the order lines are drawing, I got the correct result.

        pt1 = Geom::Point3d.new(0.98787,0.926013,0)
        pt2 = Geom::Point3d.new(0.988135,0.925025,0)
        pt3 = Geom::Point3d.new(0.977696,0.924673,0)
        Sketchup.active_model.entities.add_line(pt1,pt2)
        Sketchup.active_model.entities.add_line(pt2,pt3)
        [attachment=0:24mkndsa]<!-- ia0 -->correct.jpg<!-- ia0 -->[/attachment:24mkndsa]

        I was thinking of something linked to the precision of SU but cant explain if its the limit why the one code produces the correct result and the other not.

        Any idea appreciated.
        Yours
        Pascal

        pt1 and pt2 are less than 0.001" apart so Sketchup treats them as the same point.

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

        http://sdmitch.blogspot.com/

        1 Reply Last reply Reply Quote 0
        • ppoublanP Offline
          ppoublan
          last edited by

          Hi sdmitch,
          Sorry but do not think this is the reason cause :

          • pt1/pt2 distance is 0.0010229217956422459 inches, so equal or above 0.001 inches
          • if it was the reason, the second code would not produce different result
          • and last, in both codes, the 3 different points are correctly setup by SU, just the joining lines are incorrect
            ...
            Still looking for a solution. I could add to my code to test minimum distance longer than 0.001 inches, but in this case this would not solve the issue.
            Pascal
          1 Reply Last reply Reply Quote 0
          • jolranJ Offline
            jolran
            last edited by

            Same results while using entities.add_curve ?

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

              @ppoublan said:

              Sorry but do not think this is the reason cause :

              • pt1/pt2 distance is 0.0010229217956422459 inches, so equal or above 0.001 inches

              It is not the distance between points, it is the position of the vertices in the model.
              Note that the model has Sketchup::Vertex objects, not Geom::Point3d objects.

              Geom::Point3d objects are only virtual helper objects.

              ` xd = 0.988135 - 0.98787
              0.0002649999999999597

              yd = 0.926013 - 0.925025
              0.0009879999999999889

              pt1.x == pt2.x
              true

              pt1.y == pt2.y
              true`

              I'm not here much anymore.

              1 Reply Last reply Reply Quote 0
              • ppoublanP Offline
                ppoublan
                last edited by

                Thanks Dan,
                But then how could you explain the second example works fine ?

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

                  I think what you are seeing is a "capture effect" that happens as SketchUp post-processes the geometry to see whether a new Edge intersects or lies atop part of an existing Edge. When the new Edge passes "close enough" to a Vertex of an existing Edge, SketchUp decides they were meant to intersect at that Vertex and modifies them to make it so. In your case this amounted to redefining the Edge from pt3 to pt2 to end at pt1 instead (!). I haven't figured out the logic behind which nearby Vertex SketchUp chooses (i.e. why shift from pt2 to pt1?), but suspect it is sensitive to the order in which the Vertices are stored in some data structure, and the order depends on the order and direction in which you drew the Edges. That would explain why one of your cases works and the other gets captured.

                  I've seen similar effects in other situations such as when a new Edge passes near but not absolutely through the end of a previous one, but gets "bent" over to that end and split into two segments (this causes nasty subtle errors in some people's floorplans when they draw a bit carelessly!). There was also a post a while back in which a new Edge tried to go to a Vertex of a circle and got "sucked" over to the next one because the Edge passed too close to it.

                  The bottom line is that it is always dangerous to create geometry at sizes near SketchUp's 0.001 tolerance. It isn't worth arguing about whether the Vertices are .00002 over, since the actual tolerance logic isn't explained anywhere. Just don't try to create geometry at that sort of size. Scale up, create it, then scale down.

                  1 Reply Last reply Reply Quote 0
                  • ppoublanP Offline
                    ppoublan
                    last edited by

                    Better understand. Thanks slb for these explanation.

                    I Cant use scaling in this case as the points are the result of crossing lines, so at any scale the resulting point of two lines crossing can be very close to any other point in the model.

                    This gave me an idea for a very bad workaround. Do not like it, but it works. this way SU does not seem to try sharing same vertex...
                    pt1 = Geom::Point3d.new(0.98787,0.926013,0)
                    pt2 = Geom::Point3d.new(0.988135,0.925025,0)
                    pt3 = Geom::Point3d.new(0.977696,0.924673,0)
                    grp1 = Sketchup.active_model.entities.add_group
                    grp1.entities.add_line(pt3,pt2)
                    grp2 = Sketchup.active_model.entities.add_group
                    grp2.entities.add_line(pt2,pt1)
                    grp1.explode
                    grp2.explode

                    Thks again
                    Pascal

                    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