bluebird343
bluebird343

Reputation: 143

Hyperboloid Plotting

I did see this post: Plotting A Hyperboloid

However, it wasn't that obvious to me how the formula was translated into this:

x = a*np.cosh(u)*np.cos(v)
y = b*np.cosh(u)*np.sin(v)
z = c*np.sinh(u)

My equation is this:

(x**2 + y**2)/a + z**2/b = c

This is equation 1 found in this link: http://arxiv.org/pdf/1211.0980.pdf

I'd really like to change the a,b,c values then look at how the surface changes. What are the formulas I'd use for x,y,z or how could I get them?

When I just have an equation like this:

 z = np.sqrt(b*(c**2 - (np.cosh(u)**2)/a))

I get a bunch of Nans at the middle of the surface. ;/

Thanks!

Upvotes: 4

Views: 3498

Answers (1)

tom10
tom10

Reputation: 69182

Both expressions you refer to are valid for a hyperbaloid, but the Cartesian one is a often a bit easier (and there is a sign error in your implicit equation). For this case, sticking with your equation, the correct form is

(x**2 + y**2)/a - z**2/b = c

and a more standard expression for a circular hyperboloid would be

(x**2 + y**2)/a**2 - z**2/b**2 = 1  (or -1 for a two-sheet hyperboloid)

To plot these in matplotlib, make a meshgrid of x and y and then calculate z, like this:

from matplotlib import cm
import matplotlib.pyplot as plt
import numpy as np

fig = plt.figure()
ax = fig.gca(projection='3d')
X = np.arange(-5, 5, 0.25)
Y = np.arange(-5, 5, 0.25)
X, Y = np.meshgrid(X, Y)

Z = np.sqrt(4.*(X**2 + Y**2)/1. + 1)

xcolors = X - min(X.flat)
xcolors = xcolors/max(xcolors.flat)

surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, facecolors=cm.hot(xcolors),
    linewidth=1)

plt.show()

Here I colored by the x-values because I thought this gave a clearer plot. enter image description here Or change the +1 to -1 to get a sheet of the two sheet version: enter image description here

Upvotes: 4

Related Questions