-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEllipsoid.py
More file actions
36 lines (20 loc) · 1.14 KB
/
Ellipsoid.py
File metadata and controls
36 lines (20 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# ------------------------------------- Parametric Surface Plotting of an Ellipsoid -----------------------------------------
# The parametric equation of an Ellipsoid is (a cosθ sinΦ)i + (b sinθ sinΦ)j + (c cosΦ)k where a,b,c > 0
# a,b,c are the radius in each component and i,j,k being unit vectors in the direction of x-axis, y-axis, z-axis respectively.
# with 0 ≤ θ ≤ 2π and 0 ≤ Φ ≤ π
# These parameters may be interpreted as spherical coordinates, where θ is the polar angle
# and Φ is the azimuth angle of the point (x, y, z) of the ellipsoid.
# Code:
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
theta = np.linspace(0, 2*np.pi, 50)
phi = np.linspace(0, np.pi, 50)
theta_grid, phi_grid = np.meshgrid(theta, phi)
x_grid = 6 * np.cos(theta_grid) * np.sin(phi_grid) # taking a = 6
y_grid = 3 * np.sin(phi_grid) * np.sin(theta_grid) # taking b = 3
z_grid = 2 * np.cos(phi_grid) # taking c = 2
fig = plt.figure(figsize = (15,15))
ax = fig.add_subplot(111, projection='3d')
ax.plot_surface(x_grid, y_grid, z_grid, rstride = 2, cstride = 2, color = 'green')
plt.show()