How to create tangent arcs from Ruby without doing my own math

  1. I know how to create tangent arcs with a given radius between two line segments using the GUI.
  2. I know how to create a series of edges using Ruby

How can I have Ruby get Sketchup to do the heavy lifting of constructing a tangent arc between two edge with a given radius.

Thanks

You can use the Entities #add_arc method to create an arc curve segment.
But definitely, you need to do your own maths to calculate the parameters for that method.

There is no such a complex method in Ruby API like, fillet, chamfer, or tangent.
The only way to avoid your work to use/check extension from others, e.g.:
2D Tools | SketchUcation
TrueTangents | PluginStore | SketchUcation
Radius Tool | SketchUp Extension Warehouse
1001bit Tools (Freeware) | SketchUp Extension Warehouse

1 Like

Thank you. I will start in on the vector math.

My TrueTangents probably does what you need…
https://sketchucation.com/pluginstore?pln=TrueTangents
But the simple Fillet tool might also be sufficient…

1 Like

Here is what I came up with for future users. I am new to Ruby so I am sure this isn’t very Ruby-ish.

# construct circular arc of given radius between two intersecting lines
# lines intersect at the vertex. Points pA and pB are any points on those lines
def fillet (pA, pVertex, pB, radius)
  
  vA = (pA - pVertex).normalize!()
  vB = (pB - pVertex).normalize!()
  vNormal = vA * vB  # orientation vector

  theta = vA.angle_between vB # angle between sides
  arc_angle = Math::PI - theta # included angle of fillet

  # vector from vertex to arc center
  vCenter = (vA + vB).normalize().transform( radius / Math.sin(theta/2) ) 

   #vector from vertex to intercept on side A
  vInterceptA = vA.transform(radius/Math.tan(theta/2))
  pInterceptA = pVertex + vInterceptA
  #vector from vertex to intercept on side B
  vInterceptB = vB.transform(radius/Math.tan(theta/2))
  pInterceptB = pVertex + vInterceptB
  
  ents = Sketchup.active_model.entities
  fillet_arc = ents.add_arc(pVertex + vCenter, vInterceptB, vNormal, radius, Math::PI/2, Math::PI/2+arc_angle)
  return [pInterceptA, pInterceptB]
end

Took me a while to understand that 0 angle for arc_start wasn’t on the x-axis required as a calling parameter. Seems silly.