JSFiddle - React, Tailwind, and code Playground
JavaScript
sphericalCoordinates = function(r,O,o){
"use strict";
O = O * Math.PI / 180.0;
o = o * Math.PI / 180.0;
var x = r * Math.sin(o) * Math.cos(O);
var y = r * Math.sin(o) * Math.sin(O);
var z = r * Math.cos(o);
// normalize
// var most = Math.max(Math.abs(x),Math.abs(y),Math.abs(z))
//console.log("MOST",most);
return { x: x, y: y, z: z };
}
var rotation = {x: 0.09920761447188806, y: -3.8064632215551817, z: 0};
console.log("FORWARD",sphericalCoordinates(1,0,0.0001));
console.log("BACKWARD",sphericalCoordinates(-1,0,0.0001));
console.log("LEFT",sphericalCoordinates(1,0,90.0001));
console.log("RIGHT",sphericalCoordinates(-1,0,90.0001));