0

Is it possible to port the TCanvas.Ellipse method from Delphi

Ellipse(X1,Y1,X2,Y2);

to arc method in JavaScript ?

arc(x,y,r,sAngle,eAngle,counterclockwise);

Thanks

TLama
  • 75,147
  • 17
  • 214
  • 392
Blow ThemUp
  • 895
  • 6
  • 18
  • 29

1 Answers1

3

There is no direct, general translation; the Delphi function draws ellipses, while the JavaScript function only draws circular arcs, which are incapable of drawing ellipses (although it can be approximated).

If you were using Ellipse to draw a circle, then the conversion is simple. Calculate the center of the rectangle (square, really), and then calculate half the height or width for the radius. The documentation linked in the question already mentions the angles to use for a full circle, and clockwise or counterclockwise doesn't matter.

arc(x1+(x2-x1)/2, y1+(y2-y1)/2, (x2-x1)/2, 0, Math.PI/2);

If you want an ellipse, consider using something other than arc, like Bezier curves.

Community
  • 1
  • 1
Rob Kennedy
  • 161,384
  • 21
  • 275
  • 467