I am trying to move a point for now randomly over the surface of a sphere. currently i am trying to do this by generating random spherical coordinates and then converting these to 3d locations with the function .setFromSphericalCoords()
This is what the code looks like that generates a new random spherical coordinate 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)));
this kinda works but currently my sphere point is not really moving over the sphere but rather jumping huge distances.
I think this has to do with what values i am supplying as phi
and theta
, but the problem is that i have no clue what the value range of phi
and theta
is.
If something is not clear let me know so i can clarify!