3

I'd like to plot a rotated parabolic cylinder. Like holding one point of the plane of symmetry with two fingers and let this plane rotate about this point.

There is the rotation matrix (for the y-axis).

And the parametrised surface is:

(u,v,u**2)

I've already plotted this surface for rotations about the x-axis:

enter image description here

Below is the modified(!) code to plot the rotations about the y-axis.

from math import cos,sin,pi
import matplotlib.pyplot as plt
from matplotlib import cm

from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.auto_scale_xyz([0, 500], [0, 500], [0, 0.15])

ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')

Us = np.arange(-1, 1, 0.005)
Vs = np.arange(-1, 1, 0.005)

for ch in [0.2*i*pi for i in range(3)]: 
    Xs = Us*cos(ch) + sin(ch)*(Us**2)
    Ys = Vs
    Xs, Ys = np.meshgrid(Xs, Ys)
    Zs = -Us*sin(ch) + cos(ch)*(Us**2)
    Axes3D.plot3D(ax,Xs,Ys,Zs, alpha=0.05)

And it doesn't work. It produces nonsense. This is the output i get:

enter image description here

The operations are identical, so i really can't see why it doesn't work. Can anyone tell me what i'm doing wrong?

I need to make this work in order to just look at the way algebraic surfaces transform when subjected to certain rotations. The code above is a crudely simplified snippet of what i am currently debugging. So the answer i am hoping for regards this particular code.

4

2 に答える 2

2

明示的な回転方程式を使用する別のバージョンを次に示します。

import matplotlib as mpl
mpl.use('TkAgg')
from math import cos,sin,pi
import numpy as np
from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.auto_scale_xyz([0, 500], [0, 500], [0, 0.15])

ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')

U = np.arange(-1, 1, 0.005)
V = np.arange(-1, 1, 0.005)
def animate():
    for ch in [0.2*i*pi for i in range(3)]:
        Us, Vs = np.meshgrid(U, V)
        Xs = Us*cos(ch) + sin(ch)*(Us**2)
        Ys = Vs
        Zs = -Us*sin(ch) + cos(ch)*(Us**2)
        tmp = ax.plot_surface(Xs,Ys,Zs, alpha=0.05)
        fig.canvas.draw()
        tmp.remove()

win = fig.canvas.manager.window
fig.canvas.manager.window.after(100, animate)
plt.show()
于 2012-09-18T13:26:44.907 に答える
0

rotate_axes3d_demoax.view_initで次のように行います。

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import axes3d
plt.ion()

sin = np.sin
cos = np.cos
pi = np.pi

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.auto_scale_xyz([0, 500], [0, 500], [0, 0.15])

ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')

Us, Vs =  np.meshgrid(np.linspace(-1, 1, 200), np.linspace(-1, 1, 200))
ax.plot_surface(Us,Vs,Us**2)
for angle in range(0, 360):
    ax.view_init(angle, 30)
    plt.draw()
于 2012-09-18T12:40:11.623 に答える