This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 23392 - request: elliptical arc
Summary: request: elliptical arc
Status: RESOLVED NEEDSINFO
Alias: None
Product: HTML WG
Classification: Unclassified
Component: HTML Canvas 2D Context (show other bugs)
Version: unspecified
Hardware: PC Windows NT
: P2 normal
Target Milestone: ---
Assignee: Jay Munro
QA Contact: HTML WG Bugzilla archive list
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-09-29 16:53 UTC by Mike Kamermans
Modified: 2014-06-20 22:04 UTC (History)
4 users (show)

See Also:


Attachments

Description Mike Kamermans 2013-09-29 16:53:36 UTC
With the ellipse() function now part of the http://www.w3.org/html/wg/drafts/2dcontext/html5_canvas draft, it is surprising to see there is no elliptical arc command. I'd like to request for consideration the addition of two commands for elliptical arcs, as they are a superset of circular arcs and allow for much better curve work than using transformed circular arcs, and much faster curve work than beziers.


(1) context . ellipticArc(x, y, xRadius, yRadius, startAngle, endAngle, ellipseAngle [, anticlockwise ] )

A counterpart (and superfunction) of the regular arc command. If xRadius==yRadius, then this is identical to arc(), otherwise this will draw a (section of) an ellipse, itself rotated about x/y at a specific angle to cover all possible arcs.

(2) context . arcBetween(cx, cy, startx, starty, endx, endy)

this would draw an arc from start x/y to end x/y, over center point cx/cy, with the arcing parameters derived from these three coordinates so that canvas users don't need to calculate these. Often users don't actually want to compute exact angles, they care more about the arc lining up with specific coordinates. Having a coordinates-only function would be quite useful.

While in principle similar to drawing a Bezier from start x/y to end x/y with control points chosen so that the curve start/end tangents are correctly aligned, the math for exact arc fitting is much faster than for deriving the correct high-order bezier (necessary as a bezier curve cannot actually model an elliptical curve, a cubic curve can only approximate a little over a quarter turn before become obviously visibly wrong, and an implementation would have to derive multiple beziers to render the arc).

---

Use cases for both are simply improved shaping tools as part of the toolset offered by the canvas2d API. The lack of any elliptical arc means code that needs them (canvas games or anything pathed-based graphics in the canvas, really) currently uses artificial and very expensive code to model and render what are in essence very cheap curves. Particularly the auto-fitting arc function would make life a lot easier.
Comment 1 Jay Munro 2013-09-30 16:10:17 UTC
Interesting idea. I'm going to mark it for consideration in the Level 2 Context 2D specs, since CR is not taking any new APIs. Also, ellipse is on the at-risk list for CR, but is included in the Level 2 context.
Comment 2 Ian 'Hixie' Hickson 2013-10-09 21:20:32 UTC
How does an elliptical arc differ from the ellipse version of arcTo()?
Comment 3 Mike Kamermans 2013-10-09 21:32:16 UTC
codewise, no difference. However, the arcTo function is implicitly circle arcs, and the idea of overloading the arcTo function to also draw elliptical arcs with the only reason for doing so being its argument count seemed needlessly complicating the API.

(I couldn't see an ellipse variant in the arcTo spec in the draft, so if there already is one and missed it, I'll happily take a look at that and see if it covers all the concepts outlined in the original request)
Comment 4 Jay Munro 2014-06-20 22:04:51 UTC
In looking at the ellipse method in Canvas Context 2d, it appears that creating an elliptical arc is covered. Mike, take a look at it: 

http://www.w3.org/html/wg/drafts/2dcontext/master/#dom-context-2d-ellipse

By setting the start and end angles, it would seem to cover what you've outlined.