I'm creating an elliptical cloud of points in Three.js and have two problems that seem straight forward, but I've been stuck on now for a couple days:
- The cloud should be elliptically shaped with the longest axis on the
x
axis - currently it's oriented with the shortest axis on thex
axis - While my fiddle for the cloud looks perfectly elliptical, the working code in my file has a few points at
y = 0
on thex
axis that appear to be running to the beat of their own drummer - they are lined up like soldiers on they = 0
on either side of the ellipse to the measure oflength
(see screenshot below). Both files contain the same math for the ellipse - what's going on here?
Thanks!
The code for the elliptical cloud of points:
particleCount = 300;
for (var p = 0; p < particleCount; p++) {
// ELLIPTICAL
var length = 200; // x (major axis)
var width = 75; // y (minor axis)
var pX = (Math.random() * length);
// solve for length of vertical chord at pX:
var chord;
var rightBisector = Math.abs((length/2) - pX);
chord = (2 * length) * Math.sqrt(1 - Math.exp(2 * Math.log(rightBisector/width)));
var pY = (Math.random() * chord);
pX -= length/2; // center the cloud horizontally
pY -= chord/2; // center the cloud vertically
// END ELLIPTICAL
// Make image particle at pX, pY and add to system