In: Computer Science
please use Jupter notebook in python 3 to answer the following:
Plot the hyperbolic paraboloid given by: z = x**2/a**2 - y**2/b**2. You may use any non-negative integer values for a and b.
Code:
import numpy as np
import pptk
def f(x, y):
return x ** 2 - y ** 2
t = np.linspace(-1.0, 1.0, 100)
x, y = np.meshgrid(t, t)
z = f(x, y)
P = np.stack([x, y, z], axis=-1).reshape(-1, 3)
v = pptk.viewer(P)
v.attributes(P[:, 2])
v.set(point_size=0.005)
(Let me know if Jupyter can't import pptk, I shall give an alternate code then)
Alternate code:
from __future__ import division
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure(figsize=plt.figaspect(1)) # Square figure
ax = fig.add_subplot(111, projection='3d')
r=1;
u=np.linspace(-2,2,200);
v=np.linspace(0,2*np.pi,60);
[u,v]=np.meshgrid(u,v);
a = 1
b = 1
x = a*np.cosh(u)*np.cos(v)
y = b*np.sinh(u)
z = x**2 - y**2
ax.plot_surface(x, y, z, rstride=4, cstride=4, color='b')
plt.show()