简体   繁体   中英

Bezier curves draw stretched ellipses in HTML5 canvas

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 :

高帆布椭圆形(应为圆形)

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:

宽帆布椭圆形(应为圆形

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?

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.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM