I'm no mathematician so please take that into account in replies.
Lets say we have a sphere located at 0, 0, 0,
The radius is 0.5m
We want the surface origin to be x=0, y=0.5, z=0
I want to be able to add an angle in degrees to the x/y plane and add an angle in degrees to the z-plane and get back the xyz coordinate.
For example starting at the origin x=0, y=0.5, z=0 + 90 degrees(xy) = x=0.5, y=0, z=0 adding 90 degree to the z gives the coordinate x=0, y=0, z=0.5.
What is the equation for translating this?
In Python I've tried the following but it is not delivering the desired result:
def location_on_sphere(radius, rotation_horizontal, rotation_vertical):
elevation = radians(rotation_vertical)
alpha = radians(rotation_horizontal)
r = radius
x = r * cos(elevation) * sin(alpha)
y = r * cos(elevation) * cos(alpha)
z = r * sin(elevation)
print(str(x) + ' ' + str(y) + ' ' + str(z))
location_on_sphere(radius=0.5, rotation_horizontal=0, rotation_vertical=0)
Edit: I've updated the above code relative to comments
Results:
location_on_sphere(radius=0.5, rotation_horizontal=0, rotation_vertical=0) : x=0.0 y=0.5 z=0.0 Correct
location_on_sphere(radius=0.5, rotation_horizontal=90, rotation_vertical=0) : x=0.5 y=3.061616997868383e-17 z=0.0 Nearly correct, correct would be x=0.5, y=0, z=0, give the power to -17 then the 3.06... is just a residue, so I think this now works? I'll run some tests.
The first operation is a rotation about the $z$ axis, the second about the $y$ axis. Set the angles as $α=toradians(alpha)$ and $beta=toradians(polar)$. In total the chain of operations assembles as $$ \pmatrix{x\\y\\z} = R_y(alpha)R_z(polar)\pmatrix{0\\r\\0}\\ =\pmatrix{\cosα&0&\sinα\\0&1&0\\\sinα&0&\cosα} \pmatrix{\cosβ&-\sinβ&0\\\sinβ&\cosβ&0\\0&0&1} \pmatrix{0\\r\\0}\\ =\pmatrix{\cosα&0&\sinα\\0&1&0\\\sinα&0&\cosα} \pmatrix{-r\sinβ\\r\cosβ\\0}\\ =\pmatrix{-r\cosα\sinβ\\r\cosβ\\-r\sinα\sinβ}\\ $$