How to find the length of vector to the point on surface of sphere

48 Views Asked by At

For my work on ray tracing, I have a light source positioned at <0,0,0.5> which produce the light ray defined by two angles theta (around XY plane) and phi(around YZ plane). Here the ray makes a point on surface of unit sphere centred at origin and the point, I calculated using the following

[x,y,z] = [cos(theta).sin(phi),sin(phi).sin(phi),cos(phi)]

My question is how to calculate the length of ray from the source to the point on sphere ?

To be more clear, I consider an example. The light source 's' mounted at height from ground 0.5 m and the angle it makes is theta=20, phi=15 gives the point (x,y,z) on surface of sphere.