sketchucation logo sketchucation
    • Login
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    🛣️ Road Profile Builder | Generate roads, curbs and pavements easily Download

    How to handle units when calculating points

    Scheduled Pinned Locked Moved Plugins
    2 Posts 2 Posters 157 Views 2 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

      I am still working on my woodworking joint plugin and I am now trying to address the inches/mm so it will work in both units. I found the .to_l that makes the variables display the correct units in the input form now I am trying to figure out how to get the calculated points to also be correct for the drawing units.

      def points_DowelCircle_Comp1(x,y)
          r=@@dia/2
          @pt[0]=Geom;;Point3d.new(x+r,y,0)
          @pt[1]=Geom;;Point3d.new(x+(0.866*r),y+(0.5*r),0)
          @pt[2]=Geom;;Point3d.new(x+(0.5*r),y+(0.866*r),0)
          @pt[3]=Geom;;Point3d.new(x,y+r,0)
          @pt[4]=Geom;;Point3d.new(x-(0.5*r),y+(0.866*r),0)
          @pt[5]=Geom;;Point3d.new(x-(0.866*r),y+(0.5*r),0)
          @pt[6]=Geom;;Point3d.new(x-r,y,0)
          @pt[7]=Geom;;Point3d.new(x-(0.866*r),y-(0.5*r),0)
          @pt[8]=Geom;;Point3d.new(x-(0.5*r),y-(0.866*r),0)
          @pt[9]=Geom;;Point3d.new(x,y-r,0)
          @pt[10]=Geom;;Point3d.new(x+(0.5*r),y-(0.866*r),0)
          @pt[11]=Geom;;Point3d.new(x+(0.866*r),y-(0.5*r),0)
          
          #Debug @pt.each {|e| UI.messagebox("point = "+ e.to_s)}
          
        end #points_DowelCircle
      

      What do I need to do so these points are correct in mm and in? Do I need to apply the .to_l to each variable that is a distance or length or point in space before it is used in the equation? In this case the x,y,r variables. I have a lot of other calculations so I thought I would ask before making the changes to the program.

      Keith

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

        If the values are in inches then you won't need to convert from a float to length if you are only passing it to Point3d.new.

        Looking I your code I would have made your hard coded values into reusable variables or constants. Easier to maintain and you'll be creating less objects.

        The only time you need to convert to a Length is when you need to output the unit to the current model unit as Length.to_s will do that.
        Otherwise, make sure any hard coded lengths are in inches, or use the helper methods that converts it to Length object.

        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