def calculate_bezier_curve_points_for_arc(cx, cy, a, b, lambda_1, lambda_2, theta)
      e = lambda do |eta|
        [
          cx + a * Math.cos(theta) * Math.cos(eta) - b * Math.sin(theta) * Math.sin(eta),
          cy + a * Math.sin(theta) * Math.cos(eta) + b * Math.cos(theta) * Math.sin(eta)
        ]
      end

      ep = lambda do |eta|
        [
          -a * Math.cos(theta) * Math.sin(eta) - b * Math.sin(theta) * Math.cos(eta),
          -a * Math.sin(theta) * Math.sin(eta) + b * Math.cos(theta) * Math.cos(eta)
        ]
      end

      iterations = 1
      d_lambda = lambda_2 - lambda_1

      while iterations < 1024
        if d_lambda.abs <= Math::PI / 2.0
          # TODO : run error algorithm, see whether it meets threshold or not
          # puts "error = #{calculate_curve_approximation_error(a, b, eta1, eta1 + d_eta)}"
          break
        end
        iterations *= 2
        d_lambda = (lambda_2 - lambda_1) / iterations
      end

      (0...iterations).collect do |iteration|
        eta_a, eta_b = calculate_eta_from_lambda(a, b, lambda_1+iteration*d_lambda, lambda_1+(iteration+1)*d_lambda)
        d_eta = eta_b - eta_a

        alpha = Math.sin(d_eta) * ((Math.sqrt(4 + 3 * Math.tan(d_eta / 2) ** 2) - 1) / 3)

        x1, y1 = e[eta_a]
        x2, y2 = e[eta_b]

        ep_eta1_x, ep_eta1_y = ep[eta_a]
        q1_x = x1 + alpha * ep_eta1_x
        q1_y = y1 + alpha * ep_eta1_y

        ep_eta2_x, ep_eta2_y = ep[eta_b]
        q2_x = x2 - alpha * ep_eta2_x
        q2_y = y2 - alpha * ep_eta2_y

        {:p2 => [x2, y2], :q1 => [q1_x, q1_y], :q2 => [q2_x, q2_y]}
      end
    end
def calculate_bezier_curve_points_for_arc(cx, cy, a, b, lambda_1, lambda_2, theta)
      e = lambda do |eta|
        [
          cx + a * Math.cos(theta) * Math.cos(eta) - b * Math.sin(theta) * Math.sin(eta),
          cy + a * Math.sin(theta) * Math.cos(eta) + b * Math.cos(theta) * Math.sin(eta)
        ]
      end

      ep = lambda do |eta|
        [
          -a * Math.cos(theta) * Math.sin(eta) - b * Math.sin(theta) * Math.cos(eta),
          -a * Math.sin(theta) * Math.sin(eta) + b * Math.cos(theta) * Math.cos(eta)
        ]
      end

      iterations = 1
      d_lambda = lambda_2 - lambda_1

      while iterations < 1024
        if d_lambda.abs <= Math::PI / 2.0
          # TODO : run error algorithm, see whether it meets threshold or not
          # puts "error = #{calculate_curve_approximation_error(a, b, eta1, eta1 + d_eta)}"
          break
        end
        iterations *= 2
        d_lambda = (lambda_2 - lambda_1) / iterations
      end

      (0...iterations).collect do |iteration|
        eta_a, eta_b = calculate_eta_from_lambda(a, b, lambda_1+iteration*d_lambda, lambda_1+(iteration+1)*d_lambda)
        d_eta = eta_b - eta_a

        alpha = Math.sin(d_eta) * ((Math.sqrt(4 + 3 * Math.tan(d_eta / 2) ** 2) - 1) / 3)

        x1, y1 = e[eta_a]
        x2, y2 = e[eta_b]

        ep_eta1_x, ep_eta1_y = ep[eta_a]
        q1_x = x1 + alpha * ep_eta1_x
        q1_y = y1 + alpha * ep_eta1_y

        ep_eta2_x, ep_eta2_y = ep[eta_b]
        q2_x = x2 - alpha * ep_eta2_x
        q2_y = y2 - alpha * ep_eta2_y

        {:p2 => [x2, y2], :q1 => [q1_x, q1_y], :q2 => [q2_x, q2_y]}
      end
    end
Convert the elliptical arc to a cubic bézier curve using this algorithm:
 http://www.spaceroots.org/documents/ellipse/elliptical-arc.pdf