private void arcToBezier(double cx,double cy,double a,double b,double e1x,double e1y,double theta,double start,double sweep){
  int numSegments=(int)Math.ceil(Math.abs(sweep * 4 / Math.PI));
  double eta1=start;
  double cosTheta=Math.cos(theta);
  double sinTheta=Math.sin(theta);
  double cosEta1=Math.cos(eta1);
  double sinEta1=Math.sin(eta1);
  double ep1x=(-a * cosTheta * sinEta1) - (b * sinTheta * cosEta1);
  double ep1y=(-a * sinTheta * sinEta1) + (b * cosTheta * cosEta1);
  double anglePerSegment=sweep / numSegments;
  for (int i=0; i < numSegments; i++) {
    double eta2=eta1 + anglePerSegment;
    double sinEta2=Math.sin(eta2);
    double cosEta2=Math.cos(eta2);
    double e2x=cx + (a * cosTheta * cosEta2) - (b * sinTheta * sinEta2);
    double e2y=cy + (a * sinTheta * cosEta2) + (b * cosTheta * sinEta2);
    double ep2x=-a * cosTheta * sinEta2 - b * sinTheta * cosEta2;
    double ep2y=-a * sinTheta * sinEta2 + b * cosTheta * cosEta2;
    double tanDiff2=Math.tan((eta2 - eta1) / 2);
    double alpha=Math.sin(eta2 - eta1) * (Math.sqrt(4 + (3 * tanDiff2 * tanDiff2)) - 1) / 3;
    double q1x=e1x + alpha * ep1x;
    double q1y=e1y + alpha * ep1y;
    double q2x=e2x - alpha * ep2x;
    double q2y=e2y - alpha * ep2y;
    notifyResult("mPath.cubicTo(" + (float)q1x + "f, "+ (float)q1y+ "f, "+ (float)q2x+ "f, "+ (float)q2y+ "f, "+ (float)e2x+ "f, "+ (float)e2y+ "f);");
    eta1=eta2;
    e1x=e2x;
    e1y=e2y;
    ep1x=ep2x;
    ep1y=ep2y;
  }
}

private void arcToBezier ( double cx , double cy , double a , double b , double e1x , double e1y , double theta , double start , double sweep ) { int numSegments = ( int ) Math . ceil ( Math . abs ( sweep * 4 / Math . PI ) ) ; double eta1 = start ; double cosTheta = Math . cos ( theta ) ; double sinTheta = Math . sin ( theta ) ; double cosEta1 = Math . cos ( eta1 ) ; double sinEta1 = Math . sin ( eta1 ) ; double ep1x = ( - a * cosTheta * sinEta1 ) - ( b * sinTheta * cosEta1 ) ; double ep1y = ( - a * sinTheta * sinEta1 ) + ( b * cosTheta * cosEta1 ) ; double anglePerSegment = sweep / numSegments ; for ( int i = 0 ; i < numSegments ; i ++ ) { double eta2 = eta1 + anglePerSegment ; double sinEta2 = Math . sin ( eta2 ) ; double cosEta2 = Math . cos ( eta2 ) ; double e2x = cx + ( a * cosTheta * cosEta2 ) - ( b * sinTheta * sinEta2 ) ; double e2y = cy + ( a * sinTheta * cosEta2 ) + ( b * cosTheta * sinEta2 ) ; double ep2x = - a * cosTheta * sinEta2 - b * sinTheta * cosEta2 ; double ep2y = - a * sinTheta * sinEta2 + b * cosTheta * cosEta2 ; double tanDiff2 = Math . tan ( ( eta2 - eta1 ) / 2 ) ; double alpha = Math . sin ( eta2 - eta1 ) * ( Math . sqrt ( 4 + ( 3 * tanDiff2 * tanDiff2 ) ) - 1 ) / 3 ; double q1x = e1x + alpha * ep1x ; double q1y = e1y + alpha * ep1y ; double q2x = e2x - alpha * ep2x ; double q2y = e2y - alpha * ep2y ; notifyResult ( "mPath.cubicTo(" + ( float ) q1x + "f, " + ( float ) q1y + "f, " + ( float ) q2x + "f, " + ( float ) q2y + "f, " + ( float ) e2x + "f, " + ( float ) e2y + "f);" ) ; eta1 = eta2 ; e1x = e2x ; e1y = e2y ; ep1x = ep2x ; ep1y = ep2y ; } }
converts an arc to cubic bezier segments and records them in p .
