Last active
August 29, 2015 14:27
-
-
Save onderaltintas/0f5989c509c625fa8f27 to your computer and use it in GitHub Desktop.
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
// Creates polar arc coordinates with given x0, y0 center coordinates, radius, start angle(polar degree north = 0), | |
// end angle, number of segments. | |
function createPolarArc(xO,yO,r,startAngle,endAngle,stepSize) | |
{ | |
var ring = []; | |
ring.push([xO,yO]) | |
var cartesianStartAngle = 90 - startAngle; | |
if(startAngle > endAngle) | |
{ | |
cartesianStartAngle = (360 + cartesianStartAngle)%360 | |
} | |
var cartesianEndAngle = 90 - endAngle; | |
var angleStep = (cartesianEndAngle - cartesianStartAngle)/stepSize; | |
console.log(angleStep); | |
var currentAngle = cartesianStartAngle; | |
var radianConstant = Math.PI/180; | |
while(currentAngle != cartesianEndAngle) | |
{ | |
var x = xO + r* Math.cos(currentAngle*radianConstant); | |
var y = yO + r* Math.sin(currentAngle*radianConstant); | |
ring.push([x,y]); | |
currentAngle += angleStep; | |
} | |
var x = xO + r * Math.cos(cartesianEndAngle*radianConstant); | |
var y = yO + r* Math.sin(cartesianEndAngle*radianConstant); | |
ring.push([x,y]); | |
ring.push([xO,yO]) | |
return ring; | |
} | |
createPolarArc(0,0,10,30,60,10) | |
createPolarArc(0,0,10,30,120,10) | |
createPolarArc(0,0,10,30,210,10) | |
createPolarArc(0,0,10,30,330,10) | |
createPolarArc(0,0,10,330,30,10) | |
createPolarArc(0,0,10,210,30,10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment