Geometric Calculation with ruby
- 
  
 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 stringergroup = 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 
- 
 Are b,d,e,rise,run all variables? 
- 
 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 
- 
 @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
- 
 Thanks a lot, I need to work on 
 Geom.intersect_line_line more
- 
 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. 
Advertisement


 
                             
                             
                             
                             
                             
                             
                            