Skip to content

Instantly share code, notes, and snippets.

@clecidor
Created September 14, 2019 08:56
Show Gist options
  • Save clecidor/7e235190e32225ee934198fefdb88c19 to your computer and use it in GitHub Desktop.
Save clecidor/7e235190e32225ee934198fefdb88c19 to your computer and use it in GitHub Desktop.
circle.js
function circle(radius) {
radius = radius || (-1*radius) || 1;
const quadrant1 = [];
const quadrant2 = [];
const quadrant3 = [];
const quadrant4 = [];
const DEGREE = radius / 90;
for(let x=0; x <= radius; x+=DEGREE) {
let y = cosine(radius, x);
let xNegative = x === 0 ? 0 : (-1*x);
let yNegative = y === 0 ? 0 : (-1*y);
quadrant1.push({ x, y });
quadrant2.push({ x: xNegative, y });
quadrant3.push({ x: xNegative, y: yNegative });
quadrant4.push({ x, y: yNegative });
}
return { quadrant1, quadrant2, quadrant3, quadrant4 }
}
// Find Y (i.e. opposite/cosine) on a (X,Y) 2-dimentional graph...
// Given the hypotenuse (i.e. radius) and the X (i.e. adjacent/sine)
function cosine(hypotenuse, adjacent) {
let c = (hypotenuse**2);
let a = (adjacent**2);
let b = ((c - a)**(1/2));
return b;
}
console.log({ radius7: circle(7), radius11: circle(11) })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment