v1
9/14/2022 by chenglou -00
Setup HTML - click to add setup HTML
disable setup JavaScript
Setup JavaScript
function pointsOnEllipse1(cx, cy, rx, ry, n) {
  const points = Array(n);

  const step = Math.PI / (n / 2);
  let sin = 0;
  let cos = 1;

  const a = Math.cos(step);
  const b = Math.sin(step);

  for (let i = 0; i < n; i++) {
    points[i] = { x: cx + rx * cos, y: cy + ry * sin };
    const ts = b * cos + a * sin;
    const tc = a * cos - b * sin;
    sin = ts;
    cos = tc;
  }

  return points;
}

function pointsOnEllipse2(cx, cy, rx, ry, n) {
  const xs = Array(n);
  const ys = Array(n);

  const step = Math.PI / (n / 2);
  let sin = 0;
  let cos = 1;

  const a = Math.cos(step);
  const b = Math.sin(step);

  for (let i = 0; i < n; i++) {
    xs[i] = cx + rx * cos
    ys[i] = cy + ry * sin
    const ts = b * cos + a * sin;
    const tc = a * cos - b * sin;
    sin = ts;
    cos = tc;
  }

  return {xs, ys};
}
delete caserun single casemove downdrag and drop case


ready



let results1 = [];
for (let i = 0; i < 999; i++) {
  results1.push(
    pointsOnEllipse1(Math.floor(Math.random() * 100), Math.floor(Math.random() * 100), Math.floor(Math.random() * 100), Math.floor(Math.random() * 100), 200)
  )
}

let result = 0
for (let i = 0; i < results1.length; i++) {
  let r = results1[i]
  for (let j = 0; j < r.length; j++) {
    result += r[j].x + r[j].y
  }
}
console.log(result)
delete caserun single casemove updrag and drop case


ready



let results2 = [];
for (let i = 0; i < 999; i++) {
  results2.push(
    pointsOnEllipse2(Math.floor(Math.random() * 100), Math.floor(Math.random() * 100), Math.floor(Math.random() * 100), Math.floor(Math.random() * 100), 200)
  )
}

let result = 0
for (let i = 0; i < results2.length; i++) {
  let r = results2[i]
  for (let j = 0; j < r.xs.length; j++) {
    result += r.xs[j] + r.ys[j]
  }
}
console.log(result)
Test Case - click to add another test case
Teardown JS - click to add teardown JavaScript
Output (DOM) - click to monitor output (DOM) while test is running
RUN