@olaf000olaf You can think of a sphere as a whole bunch of circles stacked on top of each other, the circles near the middle have a radius from the axis of the sphere that is nearly equal to the radius of the sphere, the circles near the poles have a radius from the axis that approaches zero. The curve that the relationship of the radius of each circle to the height in the sphere follows is the same as the curve for a circle. In order to map angles to points on a sphere you need two angles: elevation (from 90° straight up to -90° straight down), and the azimuth (from 0° to 360°). To find the Cartesian coordinates for the point on a sphere given those angles you can first find the radius of the circle at that elevation (circle_radius = sphere_radius * cos(elevation)
) and the y
component of the vector (y = sphere_radius * sin(elevation)
). Then you can use the circle_radius
and the azimuth
angle to find the x
and z
components (x = circle_radius * cos(azimuth)
and z = circle_radius * zin(azimuth)
.
Here’s a quick example:
const radius = 100;
function setup() {
createCanvas(windowWidth, windowHeight, WEBGL);
angleMode(DEGREES);
}
function draw() {
orbitControl(2, 1, 0.05);
background(0);
strokeWeight(2);
stroke('lime');
for (let e = -80; e <= 80; e += 10) {
let cr = radius * cos(e);
let y = radius * sin(e);
for (let a = 0; a < 360; a += 20) {
let x = cr * cos(a);
let z = cr * sin(a);
point(x, y, z);
}
}
}