I want to generate uniformly distributed points within an ellipsoid that has been rotated. I have the vectors for the major, minor and intermediate axes of the rotated ellipsoid. The ellipsoid is centered at the origin. There are two problems in my opinion:
1) Finding the rotation matrix that will move the major axis from its original position (say aligned along z) onto the new major axis vector
2) Rewriting the equation of the ellipsoid as
$\vec{x} ^{T} R^{T}AR \vec{x} = 1$
and finding x,y and z so that the LHS $\leq 1$
I have attempted finding the rotation matrix this way, https://math.stackexchange.com/a/476311/475188 , where I tried to align the major axis (along z) with some arbitrary vector (both normalized) and inserting the obtained matrix into equation above, but this did not seem to work. Am I missing something or is there a simpler way?
Edit: following G Cab's answer, I've tested the solution on a unit sphere in Python, this should be returning another unit sphere, but the shape looks off. Any ideas?
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
axes = np.array([[0.83977192, -0.39189744, -0.37576525],
[0.481634, 0.8571836, 0.18238689],
[0.25062285, -0.3341447, 0.90858984]])
#Orthogonal
print np.dot(axes[0], axes[1])
print np.dot(axes[1], axes[2])
print np.dot(axes[0], axes[2])
print axes
print np.cross(axes[0],axes[1])
#Defining the matrix
r_m = np.zeros((3,3))
r_m[:,0] = axes[0,:]
r_m[:,1] = axes[1,:]
r_m[:,2] = axes[2,:]
#Taking transpose
r_m = r_m.T
x1 = np.random.uniform(-1,1,10000)
y1 = np.random.uniform(-1,1,10000)
z1 = np.random.uniform(-1,1,10000)
#Unit sphere
a = 1.
b = 1.
c = 1.
r = x1**2. + y1**2. + z1**2.
ch, = np.where(r <= 1)
x = x1[ch]*a
y = y1[ch]*b
z = z1[ch]*c
#Plotting original sphere
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.set_xlim([-1,1])
ax.set_ylim([-1,1])
ax.set_zlim([-1,1])
ax.scatter(x1[ch],y1[ch],z1[ch], s= 0.5, color = 'red')
plt.show()
#Matrix multiplying
x = x*r_m[0,0] + y*r_m[0,1] + z*r_m[0,2]
y = x*r_m[1,0] + y*r_m[1,1] + z*r_m[1,2]
z = x*r_m[2,0] + y*r_m[2,1] + z*r_m[2,2]
#Shape of output sphere looks weird
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.set_xlim([-1,1])
ax.set_ylim([-1,1])
ax.set_zlim([-1,1])
ax.scatter(x,y,z, s= 0.5, color = 'blue')
plt.show()