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

Geometric Calculation with ruby

Scheduled Pinned Locked Moved Developers' Forum
6 Posts 3 Posters 674 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.
  • D Offline
    davesexcel
    last edited by 3 Jan 2017, 17:40

    ![11.25" width](/uploads/imported_attachments/Rd18_StringerWidth.jpg "11.25" width")
    Hi,
    I am trying to get a point so that my group ends up being 11.25" wide.
    ` Sketchup.active_model.entities.clear!

    b=51.5
    d=46.5
    e=0.5
    rise=7.75
    run=10

    #<<<routed stringer
    

    group = ent.add_group(); group.name="Routed Stringer"

    ent6 = group.entities
    pts = []

    pts[0] = [0,b-(1+e),d]
    pts[1] = [0,b-(4+e),d]
    pts[2] = [0,-3, rise]
    pts[3] = [0, -3, 0]
    pts[4] = [0,(run+2.5)*0.4256, 0]
    pts[5] = [0, b-(1+e), (d-12 )]

       #add the face to the entities in the model
    face = ent6.add_face pts`
    

    The calculation I came up with will only work when the variables are a specific value, has anybody an idea how to calculate the points, so my width stays 11.25 with variable inputs?

    Thanks

    1 Reply Last reply Reply Quote 0
    • S Offline
      sdmitch
      last edited by 3 Jan 2017, 18:58

      Are b,d,e,rise,run all variables?

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

      http://sdmitch.blogspot.com/

      1 Reply Last reply Reply Quote 0
      • D Offline
        davesexcel
        last edited by 3 Jan 2017, 19:07

        Hello,
        b & d are variables, rise and run are calculated from b & d.

        for this example rise=d/6 and run=(b-(1+e))/5

        I just put in the numbers so the code can easily be copied and run

        1 Reply Last reply Reply Quote 0
        • S Offline
          sdmitch
          last edited by 3 Jan 2017, 20:08

          @davesexcel said:

          Hello,
          b & d are variables, rise and run are calculated from b & d.

          for this example rise=d/6 and run=(b-(1+e))/5

          I just put in the numbers so the code can easily be copied and run

          As I see the problem then is that points 4 & 5 need to be calculated.

          mod = Sketchup.active_model
          ent = mod.active_entities
          sel = mod.selection
          vue = mod.active_view
          Sketchup.active_model.entities.clear!
          vars = UI.inputbox(["b;","d;"],[51.5,46.5],"Routed Stringer")
          if vars
            b,d = vars; e = 0.5
            run = (b-(1+e))/5.0
            rise = d/6.0
          
            #<<<routed stringer
            group = ent.add_group(); group.name="Routed Stringer"
          
            ent6 = group.entities
            pts = []
          
            pts[0] = [0,b-(1+e),d]
            pts[1] = [0,b-(4+e),d]
            pts[2] = [0,-3, rise]
            pts[3] = [0, -3, 0]
            #calculate pts 4 & 5
            vec = pts[2].vector_to(pts[1])
            v = vec.axes[1].reverse
            tpt = pts[2].offset(v,11.25)
            pts[4]=Geom.intersect_line_line [pts[3],[0,1,0]],[tpt,vec]
            #pts[4] = [0,(run+2.5)*0.4256, 0]
            pts[5] = Geom.intersect_line_line [pts[0],[0,0,1]],[tpt,vec]
            #pts[5] = [0, b-(1+e), (d-12 )]
          
            #add the face to the entities in the model
            face = ent6.add_face pts
          end
          
          

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

          http://sdmitch.blogspot.com/

          1 Reply Last reply Reply Quote 0
          • D Offline
            davesexcel
            last edited by 4 Jan 2017, 13:20

            Thanks a lot, I need to work on
            Geom.intersect_line_line more

            1 Reply Last reply Reply Quote 0
            • T Offline
              thomthom
              last edited by 4 Jan 2017, 15:32

              Using the Geom methods, and the methods on Geom::Point3d, Geom::Vector3d as much as possible is beneficial for performance. The SketchUp API methods are implemented in C++ and will be faster than pure Ruby code.

              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
              1 / 1
              • First post
                1/6
                Last post
              Buy SketchPlus
              Buy SUbD
              Buy WrapR
              Buy eBook
              Buy Modelur
              Buy Vertex Tools
              Buy SketchCuisine
              Buy FormFonts

              Advertisement