Skip to content

Instantly share code, notes, and snippets.

@devlato
Created November 7, 2023 06:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devlato/9bc25e7657ae268cb3d192cba50d22cb to your computer and use it in GitHub Desktop.
Save devlato/9bc25e7657ae268cb3d192cba50d22cb to your computer and use it in GitHub Desktop.
Points on a circle with specified step in radians
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