vpython visualizing electric pot

时间:2017-04-10 01:58:02

标签: python 3d vpython

I am trying to visualize the electric potential for a prism using vpython. My code is working and am getting the correct 20x20 array for the data but can not figure out a way to represent this using 3D objects in vpython. For this problem, I would like to make a grid with 20x20 objects(boxes) that correspond to the 20x20 points in the array and increase the length of the boxes in the z direction as the value of the point corresponding to them in the array gets larger Is it possible to do this? thank you!

from visual import*
from visual.graph import*
import numpy as np


lenx = leny = 20




vguess= 0

x,y = np.meshgrid(np.arange(0,lenx), np.arange(0,leny))

v = np.empty((lenx,leny))
v.fill(vguess)

v[8:13,8:13] = 1

deltav = .01
maxit = 9
dV = 1

f1 = gdots(color = color.red)
while dV> 1e-5:

for i in range(1,lenx-1):
    for j in range(1,leny-1):
        if v[i,j] != 1:
            tmp = v[i,j]
            v[i,j] = .25*(v[i+1][j] + v[i-1][j] + v[i][j+1] + v[i][j-1])
            dV = abs(v[i,j]-tmp)

print v

0 个答案:

没有答案