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

    Draw infinite lines?

    Scheduled Pinned Locked Moved Developers' Forum
    18 Posts 4 Posters 741 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.
    • fredo6F Offline
      fredo6
      last edited by

      @thomthom said:

      I just want to draw these infinite guide lines that SU's tools uses some times, like the rotation or protractor tool does.
      So I'm trying to find a way for it to be in 3D so one can see the guidelines in 3d space. Otherwise I'd just use the draw2d methods.

      Have a look at what is done in FredoScale protractor tool (for instance for the rotation tool). If this is what you need I can tell you then where is the corresponding code.

      Fredo

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

        The Rotation (Free) tool?
        Looks to be drawn in the view plane, 2d. ?

        I see you've also remade SU's protractor, I guess this gizmo is something that could be make into a reusable code snippet. I've just reinvented it myself. πŸ˜’

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

        1 Reply Last reply Reply Quote 0
        • fredo6F Offline
          fredo6
          last edited by

          @thomthom said:

          The Rotation (Free) tool?
          Looks to be drawn in the view plane, 2d. ?

          Yes it is 2D (but in the plan of rotation), so the direction is 3D

          @thomthom said:

          I see you've also remade SU's protractor, I guess this gizmo is something that could be make into a reusable code snippet. I've just reinvented it myself. πŸ˜’

          I am afraid many scripters will end up rewriting their own ruby code for mimiquing the standrad SU tools (unless SU publishes some classes).

          fredo

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

            If you want 3D guides why not just use 3D guides [clines] made within the draw command and then erase them when they are no longer needed or on deactivate ? I use this in 2D tools with cpoints etc to let you snap to them on a line you have 'drawn' in temporary graphics but is not really there otherwise; they are collected into an array of entities and they are erased afterwards πŸ˜•

            TIG

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

              I want them for illustrative purposes, but I don't want my inputpoints to snap to them.
              Too bad the API lacks this feature.

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

              1 Reply Last reply Reply Quote 0
              • fredo6F Offline
                fredo6
                last edited by

                @thomthom said:

                Given a 3d vector, does anyone have any idea of drawing an infinite line using the view.draw* methods?

                Tom,

                Attached is a small code snippet (extracted and adapted from LibFredo6) which computes the 2D line simulating an infinite line in 3D.

                Say you have 2 points in 3D space: pt1_3d and pt2_3d.

                Based on the current view, you can compute the line in 2D representation
                pt1, pt2 = infinite_line(view, pt1_3d, pt2_3d)

                Then you just have to draw it
                view.draw2d GL_LINE_STRIP, pt1, pt2

                Of course, because the view can be altered by zooming and orbiting, you need

                • either to do the computation within the draw method of the Tool
                • compute it once and then only on each resume events

                Fredo


                Not a script - only code inside

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

                  You have the first point ( pt1 ) a Geom::Point3d object.
                  How about using Geom::Point3d.offset like so: (not tested)
                  vec is some vector you set

                  
                  len = model.bounds.diagonal * 2
                  pt2 = pt1.offset( vec, len )
                  xytl=view.corner(0) # topleft  an [x,y] Array
                  xybr=view.corner(3) # botright an [x,y] Array
                  xyp2=view.screen_coords(pt2) # a Point3d (ignore z value)
                  until not(xyp2.x.between?(xytl.x,xybr.x) and xyp2.y.between?(xytl.y,xybr.y))
                    len += len  # double the length
                    pt2 = pt1.offset( vec, len ) # get a new pt2
                    xyp2=view.screen_coords(pt2) # get it's new coords
                  end
                  view.draw_polyline( pt1, pt2 )
                  
                  

                  @unknownuser said:

                  Of course, because the view can be altered by zooming and orbiting, you need

                  • either to do the computation within the draw method of the Tool
                  • compute it once and then only on each resume events
                    Same goes for my example. Recompute pt2 onResume.

                  I'm not here much anymore.

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

                    What if you are able to calculate the vanishing point?

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

                    1 Reply Last reply Reply Quote 0
                    • fredo6F Offline
                      fredo6
                      last edited by

                      @thomthom said:

                      What if you are able to calculate the vanishing point?

                      This is a good idea.
                      This will allow also to use view.draw_line method and have the line be fully embedded in the 3D model (i.e. not visible when it crosses solids).

                      Of course, one need to compute this vanishing point based on the perspective view. In principle, offsetting by a distance of 1 million miles should make it!

                      Fredo

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

                        Might still be an issue, you need to use the Tool's getExtent method to return a Boundingbox big enough. But if you do that you cause the OpenGL clipping.

                        I've been trying to search for how it's generally done, infinite lines, and I think that they are drawn with special instructions in order to create such projection...

                        Not sure though... but this infinite line thing is bugging me!

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

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

                          @unknownuser said:

                          Of course, one need to compute this vanishing point based on the perspective view. In principle, offsetting by a distance of 1 million miles should make it!

                          And... what if the view is parallel...?

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

                          1 Reply Last reply Reply Quote 0
                          • fredo6F Offline
                            fredo6
                            last edited by

                            @thomthom said:

                            @unknownuser said:

                            Of course, one need to compute this vanishing point based on the perspective view. In principle, offsetting by a distance of 1 million miles should make it!

                            And... what if the view is parallel...?

                            I mean if you have a point and a direction, I guess that by offsetting the point by a huge distance will make the line looks infinite. This should be independent of the view.

                            Fredo

                            PS: do you wish to create a physical line or just draw it in a view?

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

                              Two 'infinite' parallel lines that are in fact only a few km long will appear to have a common end-point in the far distance... simply because both of their end-points will use the same screen-pixel - so they'll look like they spring from a common point BUT are actually parallel and will not.
                              Isn't it pointless to worry about this infinity-ness, provided that they 'appear' infinitely long ?

                              TIG

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

                                @tig said:

                                Isn't it pointless to worry about this infinity-ness, provided that they 'appear' infinitely long ?

                                Yes, that is what I try to do. Draw a line that appear to be infinite - that i ends in the SU horizon. Like the protractor tool does when you rotate. Or like an Guide Line does.

                                I was thinking that if you could calculate where the projection meet, you could then use that as a measurement of how long the line should be, provided you could work out what the screen point represented in world coordinates.

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

                                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