How to produce coordinates to cover a sphere with a single line?

137 views Asked by At

I am currently in this situation :

Line plotting the coordinates / Sphere of interest

I am trying to produce x,y,z coordinates which would allow me to cover specifically a sphere, in a scanning way like you can see on the red line on the figure.

I am currently using this code to produce coordinates :

Nsteps = 50
Ntours = 3
R = 10
r = 1

theta = linspace(0, 2*pi*Ntours, Nsteps, endpoint = False)
r0 = linspace(0, R, Nsteps, endpoint = False)


X01 = (r0*cos(theta))
X02 = X01[::-1]
X0 = append(X01,X02)


Y01 = (r0*sin(theta))
Y02 = Y01[::-1]*-1
Y0 = append(Y01,Y02)

Z0 = linspace(0,10,num=100)

As you can see, it is not perfect at all, and I have trouble to programm a way to force my coordinate production to respect the sphere size.

In other words, I need a script which would, with those informations entered : - Radius of Sphere - Amount of steps required - Amount of revolution

produce x,y,z coordinates which trace this path over the sphere, always being on the surface of it,in 3 arrays X, Y Z.

Because of other limitations not related to this topic, I am forced to use 50 - 100 steps, and I can not go further. So I am not looking for something to cover the whole surface of the sphere, but just cover it good enough with this quite low amount of steps.

Thank you very much for your help !

1

There are 1 answers

0
KevinG On BEST ANSWER

Spherical coordinates to the rescue: http://en.wikipedia.org/wiki/Spherical_coordinate_system#Cartesian_coordinates

This allows you to do something like

Npoints = 100

t   = np.linspace(0,np.pi,Npoints)
r   = 1

a   = 20
phi = a*t

X = r*np.sin(t)*np.cos(phi)
Y = r*np.sin(t)*np.sin(phi)
Z = r*np.cos(t)

Adjusting r for radius and a for... spirality... let's call it...