Created
May 27, 2011 13:20
-
-
Save basecode/995230 to your computer and use it in GitHub Desktop.
Raphael.fn.canvas2dArc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var round = function(value) { | |
return Math.round(value*100)/100; | |
}; | |
Raphael.fn.canvas2dArc = function(x, y, radius, aStartAngle, aEndAngle, anticlockwise) { | |
var startX, startY, endX, endY; | |
var fullCircle = 2 * Math.PI; | |
var startAngle = (anticlockwise || 0) ? aEndAngle : aStartAngle; | |
var endAngle = (anticlockwise || 0) ? Math.abs(fullCircle - aStartAngle) : aEndAngle; | |
var diffAngle = Math.abs(( startAngle > endAngle ) ? fullCircle - (startAngle - endAngle) : endAngle - startAngle); | |
// full circle | |
if ( diffAngle >= fullCircle ) { | |
return this.path([ | |
"M", x + radius, y, | |
"A", radius, radius, 0, 1, 1, x + radius * Math.cos(fullCircle), round(y + radius * Math.sin(fullCircle)) - 0.0001 | |
]); | |
} | |
startX = round(x + radius * Math.cos(startAngle)); | |
startY = round(y + radius * Math.sin(startAngle)); | |
endX = round(x + radius * Math.cos(endAngle)); | |
endY = round(y + radius * Math.sin(endAngle)); | |
return this.path([ | |
"M", startX, startY, | |
"A", radius, radius, 0, (diffAngle < Math.PI) ? 0 : 1, 1, endX, endY | |
]); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment