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

Help adding arc in ruby script

Scheduled Pinned Locked Moved Developers' Forum
10 Posts 5 Posters 2.2k 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.
  • K Offline
    ktkoh
    last edited by 20 Nov 2009, 15:05

    I am currently working on a mortise tool script based on the dado tool of Woodwrk.rb and it is working fine for square end mortise but I also want to add the capability of round mortise that is made with a router.

    This is the final section of the script that draws the mortise:

    
     po1=pt1.transform(backt) #Typical results (3.75,-0.5,0)
     po4=pt4.transform(backt) #Typical results (3.75,-0.25,0) 
     po2=pt2.transform(backt) #Typical results (0.25,-0.5,0)
     po3=pt3.transform(backt) #Typical results (0.25,-0.25,0)
     codef=@entity.definition
     cface=codef.entities.add_face po1,po2,po3,po4
    
     h=-1*@@depth	   
     cface.pushpull h
     Sketchup.active_model.commit_operation
    
    
    

    What I need to do is add a curve (half circle) that connects p1 to p4 and p2 to p3
    From the SU I see that this is the type of code that is needed and I know the centerpoints
    radius but am not sure of the start and end vectors etc.

    
    # Create a circle perpendicular to the normal or Z axis
    vector = Geom;;Vector3d.new 0,0,1
    vector2 = Geom;;Vector3d.new 1,0,0
    vector3 = vector.normalize!
    model = Sketchup.active_model
    entities = model.active_entities
    arccurve = entities.add_arc centerpoint, vector2, vector3, 10, 15, 35
    UI.messagebox arccurve 
    
    

    Your help would be appreciated
    Keith

    1 Reply Last reply Reply Quote 0
    • T Offline
      TIG Moderator
      last edited by 20 Nov 2009, 17:10

      The start/end vectors are those from the centerpoint to the start/end points of the arc.
      You have those points, so vec_start=start_point-centerpoint and vec_end=end_point-centerpoint will give these vectors.
      You need to know which end is which so that the required part of the arc gets drawn...

      TIG

      1 Reply Last reply Reply Quote 0
      • K Offline
        ktkoh
        last edited by 20 Nov 2009, 18:09

        TIG if I am reading your post correctly I define the vectors as shown?

        vec_start=po1-centerpoint
        vec_end=po4-centerpoint

        Second question will the following statement pick the face that includes the radius on the ends between point1 and point4?

        cface=codef.entities.add_face po1,po2,po3,po4

        Thanks for your help
        Keith

        1 Reply Last reply Reply Quote 0
        • T Offline
          thomthom
          last edited by 20 Nov 2009, 18:30

          @ktkoh said:

          Second question will the following statement pick the face that includes the radius on the ends between point1 and point4?

          cface=codef.entities.add_face po1,po2,po3,po4

          That won't pick a face. It will create a new one. But it will return the newly created face.

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

          1 Reply Last reply Reply Quote 0
          • T Offline
            tomot
            last edited by 21 Nov 2009, 23:11

            arcs are not easy! ....here are some code sippits from a a ruby of mine, I hope this helps!

                x=0
                y=0
                z=0
                pi = 3.141592653589793  # 180 degree angle = pi radians
                vecz = Geom;;Vector3d.new(0, 0, 1)
                vecy = Geom;;Vector3d.new(0, 1, 0)     
                vecx = Geom;;Vector3d.new(1, 0, 0) 
            
            # the 4 quadrants of a circle; are
            #
            #  pi, pi/2 | 0,pi/2
            #  ---------+--------
            # -pi/2,-pi | -pi/2,0
            #
            # the following, is an example using an arc statement incorporating the above definitions
            # this arc is 90 degress, and lies in the 2nd quadrant
            #
            model.entities.add_arc([x+@dist, y+@dist, z], vecx, vecz, @d/2, 0, pi/2, @s)
            #
            
            

            [my plugins](http://thingsvirtual.blogspot.ca/)
            tomot

            1 Reply Last reply Reply Quote 0
            • T Offline
              TIG Moderator
              last edited by 21 Nov 2009, 23:22

              It's often forgotten that you can specify angles in Ruby Sketchup in degrees directly, thus angle=180.degrees - no need to muddle on with PI and radians !

              TIG

              1 Reply Last reply Reply Quote 0
              • T Offline
                thomthom
                last edited by 21 Nov 2009, 23:25

                tomot:
                No need to define pi yourself as a variable. (first of all it'd make more sense to defined it as a constant)
                But you have it already define in the math module: Math::PI

                And you don't have to calculate the radian values yourself. The Numeric class has .degrees and .radians to do that for you. http://code.google.com/apis/sketchup/docs/ourdoc/numeric.html

                model.entities.add_arc([x+@dist, y+@dist, z], vecx, vecz, @d/2, 0, 90.degrees, @s)

                (whoop! TIG beat me to it... Except the PI part.)

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

                1 Reply Last reply Reply Quote 0
                • artmusicstudioA Offline
                  artmusicstudio
                  last edited by 3 Dec 2013, 20:05

                  hi,
                  is it also possible to draw a 3-point-arc in ruby? without defining a center?

                  i want to ad an arc along an edge, so the points would be (when edge is in y-direction):

                  arc_1 = 0,0,0
                  arc_2 = 0,y,0
                  arc_3 = x,y/2,0

                  is there a way?

                  thanx stan

                  1 Reply Last reply Reply Quote 0
                  • T Offline
                    TIG Moderator
                    last edited by 4 Dec 2013, 10:01

                    @artmusicstudio said:

                    hi,
                    is it also possible to draw a 3-point-arc in ruby? without defining a center?

                    i want to ad an arc along an edge, so the points would be (when edge is in y-direction):

                    arc_1 = 0,0,0
                    arc_2 = 0,y,0
                    arc_3 = x,y/2,0

                    is there a way?

                    thanx stan
                    Yes of course, but it needs some trigonometry...
                    Find my 'Arc_By...' tools in the PluginsStore and see the RB inside the RBZ archive.
                    The RB include algorithms for making arcs in many ways...

                    TIG

                    1 Reply Last reply Reply Quote 0
                    • artmusicstudioA Offline
                      artmusicstudio
                      last edited by 5 Dec 2013, 13:10

                      hi tig, ok,
                      let's play with some formulas 😄
                      thanx stan

                      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