问题
This method for drawing ellipses appears to be clean and elegant: http://www.williammalone.com/briefs/how-to-draw-ellipse-html5-canvas/
However, in testing it, I found that the resulting ellipses were stretched. Setting width and height equal, I got ellipses that were about 20% taller than wide. Here's the result with width = height = 50
:
![](https://i0.wp.com/i.stack.imgur.com/W5SjI.png)
To make sure that the problem was with the method itself, I tried changing the algorithm so that all the points used for the Bezier curves were rotated 90 degrees. The result:
![](https://i0.wp.com/i.stack.imgur.com/I8wfv.png)
Again, in both cases, I was expecting a 50x50 circle. Using the arc
method described at How to draw an oval in html5 canvas? works fine, generating perfect 50x50 circles (which can then be stretched into ellipses using scale
).
What's going on?
回答1:
In writing my question, I realized that I misunderstood the way Bézier curve control points work. Looking more closely at the resource I was using, the ellipse's arcs never touch the x - width / 2
and x + width / 2
boundaries in the figure. So it's not really "width" at all.
In the future, I'll stick with arc
instead of bezierCurveTo
.
(It's possible to adjust for this using a "kappa"; see this answer. That approach is preferable to arc if you're using a stroke
, not just a fill
, since scale
will cause uneven line thickness.)
来源:https://stackoverflow.com/questions/5694855/bezier-curves-draw-stretched-ellipses-in-html5-canvas