Equation for an ellipsoid pointing towards a point

53 Views Asked by At

Sorry beforehand if this question is too basic!

I would like to build an utility to create an ellipsoid pointing to a certain point in 3D space.

The equation I am using to built it: $$ x = a \, \sin(\theta) \cos(\phi) \\ y = b \, \sin(\theta) \sin(\phi) \\ z = c \, \cos(\theta) $$

The center point is $C=(0,0,0)$ and for $a= 10$, $b=1$ and $c=1$ yields https://ibb.co/kmjHp6V

I would like to build the ellipsoid pointing toward a point in space. So if the user supplied $p = (1,1,1)$ the geometry would still maintain $C=(0,0,0)$ but point towards that direction.

What are the changes to the Eq. above to account for this?

I am using python to build the geometry. The code is listed bellow:

import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure(figsize=(10, 10))
ax = fig.add_subplot(111, projection='3d')

theta = np.linspace(0, np.pi, 100)   
phi = np.linspace(0, 2*np.pi, 100) 

x = 10*np.outer( np.sin(theta), np.cos(phi) )
y = 1*np.outer( np.sin(theta), np.sin(phi) )
z = 1*np.outer( np.cos(theta), np.ones_like(phi) )

ax.plot_surface(x,y,z, alpha=0.5)
ax.set_xlim3d(-10, 10)
ax.set_ylim3d(-10, 10)
ax.set_zlim3d(-10, 10)
1

There are 1 best solutions below

6
On

Your code has to determine the longest axis of the ellipsoid, and use that as the $z'$ axis of a local $O'x'y'z'$ frame attached to the ellipsoid, that its origin $O'$ at the point $C$ which is supplied. In addition, you have a point $p$ that is also supplied by the user, from which you compute the direction of the $z'$ axis as follows

$u_3 = \dfrac{ p - C }{\| p - C \| } $

Then your code has to compute two mutually orthogonal unit vectors $u_1$ and $u_2$ that are orthogonal to the vector $u_3$ calculated above. There is an infinite number of ways to select the set $\{u_1, u_2 \}$. Now a rotation matrix representing the frame $O'x'y'z'$ rigidly attached to the ellipsoid is given by

$R = [u_1, u_2, u_3] $

$R$ is a $3 \times 3$ matrix whose columns are the three unit vectors $u_1, u_2, u_3 $. Assuming the semi-axes lengths are $a,b,c$ with $ a \le b \lt c $, then in the frame $O'x'y'z'$ we have

$ x' = a \sin(\theta) \cos(\phi) \\ y' = b \sin(\theta) \sin(\phi) \\ z' = c \cos(\theta) $

If $r'=[x',y',z']^T$ is the coordinate vector of a point on the ellipsoid in the local $O'x'y'z'$ frame, and $r=[x,y,z]^T $ is the corresponding coordinate vector in the world frame then

$ r = C + R r' $

And this will specify the ellipsoid in terms of the parameters $\theta \in [0, \pi] $ and $\phi \in [0, 2 \pi]$.