# How to rotate points on spherical cap with specific theta and phi?

I generate $$N=1000$$ points in spherical cap $$\{\rho = 10, 0 \deg<\theta<30 \deg, 0<\phi<2pi\}$$.

And now I want to rotate these points together such that the center of the cap goes to the specific theta and phi with the distances to other points unchanged.

I first try to add the specific theta and phi to the positions of all points, but with the spherical coordinates, it doesn't work. (It becomes a ring T_T)

Any one can help me to rotate all points together to such that the center of the cap goes to the specific theta and phi with the distances to other points unchanged. Or please give me some advice. Thanks in advance.

Here's my code in python.

from math import *
import numpy as np

def polarToxyz(polar_cord):  # theta, phi radian
r = polar_cord[0]
theta = polar_cord[1]
phi = polar_cord[2]
return [r * sin(theta) * cos(phi), r * sin(theta) * sin(phi), r * cos(theta)]

theta_prime_deg = 30
theta_prime_rad = theta_prime_deg * np.pi / 180

delta_theta_deg = 0
delta_theta_rad = delta_theta_deg * np.pi / 180

delta_phi_deg = 0
delta_phi_rad = delta_phi_deg * np.pi / 180

list_x = []
list_y = []
list_z = []
for i in range(numbPoints):
rho = 10
phi = 2 * np.pi * np.random.uniform(0,1)

[x,y,z] = polarToxyz([rho, theta, phi])
list_x.append(x)
list_y.append(y)
list_z.append(z)

drawFig3D(list_x, list_y, list_z)


Rodrigues' rotation formula: https://en.wikipedia.org/wiki/Rodrigues%27_rotation_formula is an elegant way to rotate a vector around an axis by a certain angle. You can first rotate by $$\phi$$ around the $$y$$-axis, then rotate around the $$z$$-axis by $$\theta$$, and that should work but you should check the results, since they'll vary based on how you set up your coordinate systems.

It's not elegant, but unless the cap is very small, you might want to consider just randomly generating points on the surface and use the dot product to take the angle with a vector through the center of the cap, and throwing out any points with too large an angle.