Last active
May 10, 2017 11:52
-
-
Save shinout/ad8457267950f2174fec3d3fc7594ece to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** | |
* @param {number} n: 正n角形 | |
* @param {number} r: 正n角形の中心から頂点への距離 | |
* @return Array<{x: number, y: number }>: 座標 | |
*/ | |
function getRectanglePoints(n, r) { | |
// canvasに書かれる | |
const thetaUnit = Math.PI * 2 / n | |
const points = [] | |
for (let i = 0; i < n; i++) { | |
points.push(polarToXY(r, thetaUnit * i)) | |
} | |
return points | |
} | |
function polarToXY(r, theta) { | |
return { | |
x: r * Math.round(Math.cos(theta) * 1000) / 1000, | |
y: r * Math.round(Math.sin(theta) * 1000) / 1000 | |
} | |
} | |
module.exports = getRectanglePoints |
This file contains hidden or 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
function getRaderChartPoints(r, rates) { | |
const thetaUnit = Math.PI * 2 / rates.length | |
return rates.map((rate, i) => polarToXY(r * rate, thetaUnit * i)) | |
} | |
function polarToXY(r, theta) { | |
return { | |
x: r * Math.round(Math.cos(theta) * 1000) / 1000, | |
y: r * Math.round(Math.sin(theta) * 1000) / 1000 | |
} | |
} | |
module.exports = getRaderChartPoints |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment