Davidto - 8 months ago 44

Javascript Question

I have a orbit of length 200. But it is centered around a sun of radius 0 (length 0). Now I want to expand the sun to have a radius of 1 and "push" out the outer orbits as well.

The XYZ coordinates look like this:

`[-6.76, 5.75, -1.06],`

[-6.95, 5.54, -0.91],

[-7.13, 5.33, -0.75],

[-7.31, 5.11, -0.58]

... followed by 196 more coordinates

I tried tried a lot of things to make the circle bigger

`* radius`

`/ someNumbers`

But i lost it when i made an

`if`

`If(the x coordination > 0)`

the x coordination += 1;

}

Else{

the x coordination += 1;

}

And also for Y and Z but when they came close to the 1 and -1 position of that axis they skipped to the other side.

Creating a line (with the width of 1 on both sides) of emptiness along the axis.

Result of MBo's awnser(view from above):

`// arrayIndex is a number to remember at which point it is in the orbit array`

satellites.forEach(function (element) {

if (element.arrayIndex>= element.satellite.coordinates.length) {

element.arrayIndex= 0;

}

var posX = element.satellite.coordinates[element.arrayIndex][0];

var posY = element.satellite.coordinates[element.arrayIndex][1];

var posZ = element.satellite.coordinates[element.arrayIndex][2];

R = Math.sqrt(posX^2 + posY^2 + posZ^2);

cf = (R + earthRadius) / R;

xnew = posX * cf;

ynew = posY * cf;

znew = posZ * cf;

// var posX = earthRadius * (element.satellite.coordinates[element.test][0] / (200 * earthRadius) * earthRadius);

// var posY = earthRadius * (element.satellite.coordinates[element.test][1] / (200 * earthRadius) * earthRadius);

// var posZ = earthRadius * (element.satellite.coordinates[element.test][2] / (200 * earthRadius) * earthRadius);

// divide by 100 to scale it down some more

element.position.x = xnew / 100;

element.position.y = ynew / 100;

element.position.z = znew / 100;

element.arrayIndex= element.arrayIndex+ 1;

});

Answer Source

You have orbit radius

```
/////////R = Sqrt(x^2 + y^2 + z^2)
Edit to avoid confusion:
R = Sqrt(x * x + y * y + z * z)
```

You need to modify coordinates to make orbit radius `R+r`

. To preserve orbit form, for every point find it's R, and multiply all components by coefficient `(R+r)/R`

```
R = Sqrt(x^2 + y^2 + z^2)
cf = (R + r) / R
xnew = x * cf
ynew = y * cf
znew = z * cf
```