jambolo / drawArc

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

Home Page:http://jambolo.github.io#drawArc

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

About

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

http://jambolo.github.io#drawArc

License:MIT License


Languages

Language:CoffeeScript 83.1%Language:HTML 9.5%Language:CSS 7.4%