LISP to Math formula / Ruby code

The “sort of” translation to SketchUp Ruby is …

# Given a SketchUp ArcCurve object, returns the arc's start point, it's bulge
# and it's end point.
# @param arc_curve [Sketchup::ArcCurve]
# @return [Array<Geom::Point3d, Float, Geom::Point3d>]
def arc_to_bulge( arc_curve )
  pi = Math::PI
  c  = arc_curve.center
  r  = arc_curve.radius
  # Convert angles from radions to degrees:
  a1 = arc_curve.start_angle.radians
  a2 = arc_curve.end_angle.radians
  #
  start_point = arc_curve.first_edge.start.position
  end_point   = arc_curve.last_edge.end.position
  #
  # Define a Lambda (ie, an anonymous function) ...
  func = ->(a) { Math.sin(a) / Math.cos(a) }
  bulge = func.call(
    # ... and immediately call the lambda where the argument is:
    (pi + pi + (a2 - a1)).remainder(pi + pi) / 4.0
  )
  return start_point, bulge, end_point
end

I say “sort_of” because I did not recreate AutoLISP’s polar function.


NOTE: I did not examine the function (method) for correctness. The example LISP function most likely relies upon assumptions in the AutoCAD geometric model.

For example, what is the assumed angular datum (vector) for the angles and does it matter if it differs in the SketchUp geometric model ?

Also, in SketchUp, a developer can assign whatever angular datum (vector) they wish as the 2nd argument to Sketchup::Entities#add_arc, but it is usually set to X_AXIS.

However, if it is set differently, then both the getter methods Skethcup::ArcCurve#start_angle and Skethcup::ArcCurve#start_angle return values relative to the arcurve’s Skethcup::ArcCurve#xaxis vector.