How to handle units when calculating points
-
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
-
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.
Advertisement