Currently, I am attempting to animate a point moving randomly across the surface of a sphere. My approach involves generating random spherical coordinates and then converting them into 3D locations using the function .setFromSphericalCoords()
.
This is the snippet of code that produces a new random spherical coordinate on each frame:
element.kralenSpherical.phi += Math.random() * 2 -1;
if(element.kralenSpherical.phi <= 0 ) element.kralenSpherical.phi = 0;
else if(element.kralenSpherical.phi >= 180 ) element.kralenSpherical.phi = 180;
element.kralenSpherical.theta += Math.random() * 2 -1;
if(element.kralenSpherical.theta >= 360 ) element.kralenSpherical.theta = 0;
else if(element.kralenSpherical.theta <= 0) element.kralenSpherical.theta = 360;
element.kraal.position.copy(element.BaseLocation.clone().add(sphericalVector.setFromSphericalCoords(element.kralenSpherical.radius, element.kralenSpherical.phi, element.kralenSpherical.theta)));
Although this approach somewhat works, my point seems to be making large jumps rather than smoothly moving across the sphere.
I suspect that the issue lies in the values I am assigning to phi
and theta
, but unfortunately, I am unsure about the range of these values.
If you require further clarification, please let me know!