单位立方体各个面上的法向量,向量场以及每个面上的通量

单位立方体各个面上的法向量,向量场 F = ( x , y , z ) \mathbf{F} = (x, y, z) F=(x,y,z) 以及每个面上的通量

flyfish
假设我们有一个单位立方体,向量场 F = ( x , y , z ) \mathbf{F} = (x, y, z) F=(x,y,z) 在该立方体上。

  1. 法向量 :单位立方体的每个面都有一个法向量。例如:
  • x = 1 x = 1 x=1 的面上,法向量为 n = ( 1 , 0 , 0 ) \mathbf{n} = (1, 0, 0) n=(1,0,0)

  • y = 1 y = 1 y=1 的面上,法向量为 n = ( 0 , 1 , 0 ) \mathbf{n} = (0, 1, 0) n=(0,1,0)

  • z = 1 z = 1 z=1 的面上,法向量为 n = ( 0 , 0 , 1 ) \mathbf{n} = (0, 0, 1) n=(0,0,1)

  1. 通量 :计算向量场 F \mathbf{F} F 穿过每个面的通量:
  • x = 1 x = 1 x=1 的面上,通量为:
    ∬ 面  x = 1 F ⋅ d S = ∬ 面  x = 1 ( 1 , y , z ) ⋅ ( 1 , 0 , 0 )   d y   d z = ∬ 面  x = 1 1   d y   d z = 1 \iint_{\text{面 } x=1} \mathbf{F} \cdot d\mathbf{S} = \iint_{\text{面 } x=1} (1, y, z) \cdot (1, 0, 0) \, dy \, dz = \iint_{\text{面 } x=1} 1 \, dy \, dz = 1  x=1FdS= x=1(1,y,z)(1,0,0)dydz= x=11dydz=1

类似地,在其他面上计算得到的通量分别为1,总的通量为6(因为单位立方体有6个面,每个面上的通量为1)
在这里插入图片描述

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d.art3d import Poly3DCollection
from matplotlib.animation import FuncAnimation, PillowWriter

# 创建单位立方体的顶点
vertices = np.array([[0, 0, 0],
                     [1, 0, 0],
                     [1, 1, 0],
                     [0, 1, 0],
                     [0, 0, 1],
                     [1, 0, 1],
                     [1, 1, 1],
                     [0, 1, 1]])

# 定义单位立方体的各个面
faces = [[vertices[j] for j in [0, 1, 2, 3]],  # z=0
         [vertices[j] for j in [4, 5, 6, 7]],  # z=1
         [vertices[j] for j in [0, 3, 7, 4]],  # y=0
         [vertices[j] for j in [1, 2, 6, 5]],  # y=1
         [vertices[j] for j in [0, 1, 5, 4]],  # x=0
         [vertices[j] for j in [2, 3, 7, 6]]]  # x=1

# 定义单位立方体各个面的法向量
normals = np.array([[0, 0, -1],
                    [0, 0, 1],
                    [0, -1, 0],
                    [0, 1, 0],
                    [-1, 0, 0],
                    [1, 0, 0]])

# 定义向量场 F = (x, y, z)
def vector_field(x, y, z):
    return np.array([x, y, z])

# 创建动画
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.set_xlim(-0.5, 1.5)
ax.set_ylim(-0.5, 1.5)
ax.set_zlim(-0.5, 1.5)

def update(frame):
    ax.clear()
    ax.set_xlim(-0.5, 1.5)
    ax.set_ylim(-0.5, 1.5)
    ax.set_zlim(-0.5, 1.5)
    
    face = faces[frame]
    normal = normals[frame]
    poly3d = [[face[0], face[1], face[2], face[3]]]
    ax.add_collection3d(Poly3DCollection(poly3d, alpha=0.5, color='cyan'))
    
    center = np.mean(face, axis=0)
    ax.quiver(center[0], center[1], center[2], normal[0], normal[1], normal[2], color='red', length=0.5)
    
    # 绘制向量场
    X, Y, Z = np.meshgrid(np.linspace(0, 1, 2), np.linspace(0, 1, 2), np.linspace(0, 1, 2))
    U, V, W = vector_field(X, Y, Z)
    ax.quiver(X, Y, Z, U, V, W, color='blue', alpha=0.3)
    
    ax.text2D(0.05, 0.95, f"Face {frame+1} with Normal Vector", transform=ax.transAxes)
    ax.text2D(0.05, 0.90, "Red Arrow: Normal Vector", transform=ax.transAxes, color='red')
    ax.text2D(0.05, 0.85, "Blue Arrows: Vector Field F = (x, y, z)", transform=ax.transAxes, color='blue')
    ax.text2D(0.05, 0.80, f"Flux through face: {np.dot(vector_field(center[0], center[1], center[2]), normal)}", transform=ax.transAxes)
    
    ax.set_xlabel('X')
    ax.set_ylabel('Y')
    ax.set_zlabel('Z')

ani = FuncAnimation(fig, update, frames=len(faces), repeat=True,interval=1000)
writer = PillowWriter(fps=1)
ani.save('unit_cube_normals_flux.gif', writer=writer)

plt.show()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

二分掌柜的

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值