I am working on a project where I need to (as a 2d point) walk around a 3d sphere. I am having trouble figuring out how to achieve this without polar distortion. Basically I want to have Move Forward, Backward, Left, and Right, as well as Turn Left, and Turn Right. I've been trying to get this working with spherical coordinates, but my functions seem to be incorrect. What can I do to get this working? (I am making this in JavaScript, using the p5.js library)
Currently, I'm trying to map an x, and y variable to spherical space's phi, and theta respectively. It doesn't seem to be working, though, and I'm not sure whether, correctly implemented, the point would move in Great Circles.
I'm also using an angle variable, to move x, and y by (cos(A), sin(A)), but I'm not sure if this is working either.
I think what I need to do is related to Great Circle Navigation, but I don't understand the mathematics behind it.
Link to my current version: https://editor.p5js.org/hpestock/sketches/FXtn82-0k
Current code looks something like
var X,Y,Z;
X=0;
Y=0;
Z=0;
var A=0;
var scaler = 100;
var MOVE_FORWARD = true;
var MOVE_BACKWARD= false;
var MOVE_LEFT = false;
var MOVE_RIGHT = false;
var TURN_LEFT = false;
var TURN_RIGHT = false;
//var i=0;
var x = 0;
var y = 0;
function setup() {
createCanvas(400, 400, WEBGL);
x= 0;
y= 0;
A= 0;
background(220);
}
function keyPressed(){
if(key == "w"){
MOVE_FORWARD = true;
}else if(key == "ArrowLeft"){
TURN_LEFT = true;
}else if(key == "ArrowRight"){
TURN_RIGHT = true;
}
}
function keyReleased(){
if(key == "w"){
MOVE_FORWARD = false;
}else if(key == "ArrowLeft"){
TURN_LEFT = false;
}else if(key == "ArrowRight"){
TURN_RIGHT = false;
}
}
function draw() {
if(MOVE_FORWARD){
x+=0.005*cos(A);
y+=0.005*sin(A);
}
if(TURN_LEFT){
A+=PI/64;
}
if(TURN_RIGHT){
A-=PI/64;
}
var xyz = Sph(1,y,x);
X=xyz[0];
Y=xyz[1];
Z=xyz[2];
background(220);
sphere(scaler);
push();
translate(X*scaler,Y*scaler,Z*scaler);
sphere(5);
pop();
/*i+=PI/32;
if(i>2*PI){
i=0;
}*/
}
function Move(a,d){
//
}
function Sph(p,t,h){
//p = radius
//t (theta) = 2d rotation
//h (phi) = 3d roation
return ([p*cos(h)*cos(t),p*cos(h)*sin(t),p*sin(h)]);
//x=ρsinφcosθ,y=ρsinφsinθ, and z=ρcosφ
}