曲线通过绕着一个轴旋转可以生成三维旋转曲面
flyfish
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
# 设置图形
fig = plt.figure(figsize=(12, 6))
# 子图1: 绘制曲线 z = y^2
ax1 = fig.add_subplot(121, projection='3d')
# 定义曲线 z = y^2
y = np.linspace(-1, 1, 200) # 缩小范围
z = y**2
ax1.plot(np.zeros_like(y), y, z, color='r', label=r'$z=y^2$')
# 设置子图1的显示参数
ax1.set_xlabel('X')
ax1.set_ylabel('Y')
ax1.set_zlabel('Z')
ax1.set_xlim(-1.5, 1.5)
ax1.set_ylim(-1.5, 1.5)
ax1.set_zlim(0, 2)
ax1.legend()
# 设置刻度线和标签
ax1.set_xticks(np.arange(-1.5, 1.5, 0.5))
ax1.set_yticks(np.arange(-1.5, 1.5, 0.5))
ax1.set_zticks(np.arange(0, 2, 0.5))
# 设置坐标轴线颜色
ax1.xaxis._axinfo['grid'].update(color='blue', linestyle='--', linewidth=0.5)
ax1.yaxis._axinfo['grid'].update(color='green', linestyle='--', linewidth=0.5)
ax1.zaxis._axinfo['grid'].update(color='purple', linestyle='--', linewidth=0.5)
# 隐藏背景面
ax1.xaxis.pane.fill = False
ax1.yaxis.pane.fill = False
ax1.zaxis.pane.fill = False
# 调整视角
ax1.view_init(elev=20, azim=60)
# 子图2: 绘制旋转抛物面 z = x^2 + y^2
ax2 = fig.add_subplot(122, projection='3d')
# 定义旋转抛物面的方程
x = np.linspace(-1, 1, 50) # 缩小范围
y = np.linspace(-1, 1, 50)
x, y = np.meshgrid(x, y)
z_surface = x**2 + y**2
# 绘制曲面
ax2.plot_surface(x, y, z_surface, cmap='viridis', alpha=0.8)
ax2.set_title('Surface: $z = x^2 + y^2$')
# 设置子图2的显示参数
ax2.set_xlabel('X')
ax2.set_ylabel('Y')
ax2.set_zlabel('Z')
ax2.set_xlim(-1.5, 1.5)
ax2.set_ylim(-1.5, 1.5)
ax2.set_zlim(0, 2)
# 设置刻度线和标签
ax2.set_xticks(np.arange(-1.5, 1.5, 0.5))
ax2.set_yticks(np.arange(-1.5, 1.5, 0.5))
ax2.set_zticks(np.arange(0, 2, 0.5))
# 设置坐标轴线颜色
ax2.xaxis._axinfo['grid'].update(color='blue', linestyle='--', linewidth=0.5)
ax2.yaxis._axinfo['grid'].update(color='green', linestyle='--', linewidth=0.5)
ax2.zaxis._axinfo['grid'].update(color='purple', linestyle='--', linewidth=0.5)
# 隐藏背景面
ax2.xaxis.pane.fill = False
ax2.yaxis.pane.fill = False
ax2.zaxis.pane.fill = False
# 调整视角
ax2.view_init(elev=20, azim=60)
#plt.tight_layout()
plt.show()
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.animation as animation # 添加这一行用于保存 GIF
# 创建图形
fig = plt.figure(figsize=(8, 6))
ax = fig.add_subplot(111, projection='3d')
# 定义原始曲线 z = y^2
y = np.linspace(-1, 1, 100)
z = y**2
x = np.zeros_like(y)
# 绘制初始曲线
ax.plot(x, y, z, color='r', label=r'$z=y^2$')
# 定义旋转函数
def update(theta):
ax.clear() # 清除当前坐标轴
ax.plot(x, y, z, color='r', label=r'$z=y^2$') # 重新绘制曲线
# 参数化形式:r = y, x = r * cos(theta), y = r * sin(theta)
for i in range(len(y)):
r = abs(y[i])
x_rot = r * np.cos(theta)
y_rot = r * np.sin(theta)
z_rot = z[i]
ax.plot([0, x_rot], [y[i], y_rot], [z[i], z_rot], color='b', alpha=0.5)
ax.set_xlim(-1.5, 1.5)
ax.set_ylim(-1.5, 1.5)
ax.set_zlim(0, 2)
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
ax.set_title('Rotation of Curve $z = y^2$ around Z-axis')
ax.legend()
# 创建动画
ani = FuncAnimation(fig, update, frames=np.linspace(0, 2*np.pi, 60), interval=100)
# 保存为 GIF 文件
ani.save("rotation.gif", writer="pillow") # 使用 pillow writer 保存为 GIF
plt.show()
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from matplotlib.animation import FuncAnimation
# 定义参数化的曲线方程 z = y^2
def curve_y(t):
return t
def curve_z(t):
return t**2
# 创建一个三维图形
fig = plt.figure(figsize=(10, 8))
ax = fig.add_subplot(111, projection='3d')
# 生成参数 t 的值
t_values = np.linspace(-1, 1, 100)
# 绘制原始曲线(红色)
ax.plot(np.zeros_like(t_values), curve_y(t_values), curve_z(t_values), color='r', lw=2, label='Original Curve')
# 设置坐标轴标签
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
ax.set_title('Rotation of Curve $z = y^2$ around Z-axis')
# 显示图例
ax.legend()
# 定义动画函数
def update(frame):
ax.clear()
# 重新绘制原始曲线
ax.plot(np.zeros_like(t_values), curve_y(t_values), curve_z(t_values), color='r', lw=2, label='Original Curve')
# 计算旋转后的坐标
theta_values = np.linspace(0, frame, 100)
T, Theta = np.meshgrid(t_values, theta_values)
X = curve_y(T) * np.cos(Theta)
Y = curve_y(T) * np.sin(Theta)
Z = curve_z(T)
# 绘制旋转曲面
ax.plot_surface(X, Y, Z, alpha=0.6, rstride=5, cstride=5, color='b', edgecolor='none')
# 设置坐标轴
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
ax.set_xlim(-1.5, 1.5)
ax.set_ylim(-1.5, 1.5)
ax.set_zlim(0, 2)
ax.set_title('Rotation of Curve $z = y^2$ around Z-axis')
ax.legend()
# 创建动画
anim = FuncAnimation(fig, update, frames=np.linspace(0, 2 * np.pi, 60), interval=100)
anim.save("rotation1.gif", writer="pillow")
# 显示动画
plt.show()
坐标转换
给定一个二维曲线
z
=
f
(
y
)
z = f(y)
z=f(y),如果我们将其绕着
z
z
z 轴旋转,则生成一个三维旋转体。在这个例子中,曲线是
z
=
y
2
z = y^2
z=y2。
要描述旋转体,可以使用柱坐标系或直接使用直角坐标系。我们采用直角坐标系,利用参数化的方法来分析。
-
二维曲线参数化 :给定曲线 z = y 2 z = y^2 z=y2 可以参数化为:xyz x = 0 , y = y , z = y 2 . \begin{align*} x &= 0, \\ y &= y, \\ z &= y^2. \end{align*} xyz=0,=y,=y2.
-
绕 z z z 轴旋转 :假设我们绕 z z z 轴旋转一个角度 θ \theta θ,那么在三维空间中可以使用以下参数化形式:xyz x = r cos θ , y = r sin θ , z = f ( r ) , \begin{align*} x &= r \cos \theta, \\ y &= r \sin \theta, \\ z &= f(r), \end{align*} xyz=rcosθ,=rsinθ,=f(r),
其中 r r r 是半径,等于 y y y 的绝对值: r = ∣ y ∣ r = |y| r=∣y∣。
3. 代入并得出方程
对于曲线
z
=
y
2
z = y^2
z=y2,我们有
z
=
r
2
z = r^2
z=r2(因为
y
=
r
y = r
y=r 时,
z
=
y
2
z = y^2
z=y2)。
旋转之后的三维曲面表达式为:
z
=
r
2
=
(
x
2
+
y
2
)
z = r^2 = (x^2 + y^2)
z=r2=(x2+y2)
4. 结论
旋转曲线 z = y 2 z = y^2 z=y2 绕着 z z z 轴旋转形成的曲面方程是: z = x 2 + y 2 z = x^2 + y^2 z=x2+y2
直观理解
当曲线 z = y 2 z = y^2 z=y2 绕 z z z 轴旋转时,每个点 ( 0 , y , y 2 ) (0, y, y^2) (0,y,y2) 旋转形成一个圆,这个圆位于平面 z = y 2 z = y^2 z=y2 上,并且在 x y xy xy 平面上的投影是半径为 ∣ y ∣ |y| ∣y∣ 的圆。由于 y y y 可以为负数,曲面方程 z = x 2 + y 2 z = x^2 + y^2 z=x2+y2 代表了由这些圆形成的抛物面。
-
定义曲线 :假设有一条位于 x − y x-y x−y 平面上的曲线 C C C,可以通过参数方程组表示为: x = x ( t ) , y = y ( t ) x = x(t), \quad y = y(t) x=x(t),y=y(t)
其中, t t t 是参数。 -
曲线旋转 :当这条曲线绕 z z z 轴旋转时,曲线上的每一个点都会沿着一个圆周运动。旋转角度用 θ \theta θ 表示。
-
旋转后的坐标 :对于曲线上任意一点 ( x , y ) (x, y) (x,y),绕 z z z 轴旋转 θ \theta θ 角度后的坐标为: X = x ( t ) cos θ − y ( t ) sin θ X = x(t)\cos\theta - y(t)\sin\theta X=x(t)cosθ−y(t)sinθ
Y = x ( t ) sin θ + y ( t ) cos θ Y = x(t)\sin\theta + y(t)\cos\theta Y=x(t)sinθ+y(t)cosθ
Z
=
z
(
t
)
Z = z(t)
Z=z(t)
因为旋转是围绕
z
z
z 轴发生的,所以
z
z
z 坐标保持不变。
- 旋转曲面方程 :要得到旋转曲面的方程,我们可以考虑旋转后的点在极坐标系中的表示。给定 Z Z Z 值,对于旋转曲面上的点,可以表示为: r 2 = X 2 + Y 2 = ( x ( t ) ) 2 + ( y ( t ) ) 2 r^2 = X^2 + Y^2 = (x(t))^2 + (y(t))^2 r2=X2+Y2=(x(t))2+(y(t))2
Z = z ( t ) Z = z(t) Z=z(t)
- 旋转曲面的例子 :对于特定例子
z
=
y
2
z = y^2
z=y2,将其绕
z
z
z 轴旋转后,得到旋转曲面的方程为:
Z
=
x
2
+
y
2
Z = x^2 + y^2
Z=x2+y2
其中 x = r cos θ x = r\cos\theta x=rcosθ 和 y = r sin θ y = r\sin\theta y=rsinθ,因此最终的旋转曲面方程为: Z = X 2 + Y 2 Z = X^2 + Y^2 Z=X2+Y2