Created
November 7, 2023 06:42
-
-
Save devlato/9bc25e7657ae268cb3d192cba50d22cb to your computer and use it in GitHub Desktop.
Points on a circle with specified step in radians
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
const step = Math.PI / 20; // step in radians | |
const raduus = 2.0; | |
const center = { x: 3.0, y: 2.0 }; // [x, y] | |
const points = []; | |
for (let angle = 0; angle < Math.PI * 2; angle += step) { | |
const initPoint = { x: 0.0, y: raduus }; | |
const rotatedPoint = { | |
x: initPoint.x * Math.cos(angle) - initPoint.y * Math.sin(angle), | |
y: initPoint.x * Math.sin(angle) + initPoint.y * Math.cos(angle), | |
}; | |
const translatedPoint = { | |
x: rotatedPoint.x + center.x, | |
y: rotatedPoint.y + center.y, | |
}; | |
points.push(translatedPoint); | |
} | |
console.log(points.map(({ x, y}) => `[${x.toFixed(2)}, ${y.toFixed(2)}]`).join(',\n')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment