Skip to content
This repository has been archived by the owner on Jan 23, 2022. It is now read-only.
/ drawArc Public archive

Computes the first parameter of the canvas arcTo function given a radius

License

Notifications You must be signed in to change notification settings

jambolo/drawArc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

drawArc

Draws an arc of a given radius between two points

Typically, the HTML canvas arcTo method is used to draw rounded corners and determining the values of the parameters is generally trivial because the first endpoint is simply the corner. However, computing the first endpoint in the case of drawing a generic arc is complicated. The drawArc method does that computation for you.

The Math

Diagram

Given a starting point, P1, an endpoint, P2, and a radius, r, compute a point, Q, such that P1Q and P2Q are tangent at P1 and P2 to a circle with the given radius with P2 counter-clockwise from P1.

Derivation

API

drawArc(context, x1, y1, x2, y2, radius)

  • context - HTML drawing context
  • x1, y1 - start of the arc
  • x2, y2 - end of the arc
  • radius - radius of curvature