0

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
  • It's not clear what you are asking. Do you want a solution in matplotlib or in vpython? – ImportanceOfBeingErnest Apr 10 '17 at 14:23
  • @ImportanceOfBeingErnest vpython if possible – Ty Patterson Apr 10 '17 at 19:53
  • So I removed the matplotlib tag and added [vpython]. You should in any case be more specific about the actual problem: What have you tried and how did it fail? See [ask]. I would vote to leave this question open, as it already provides an example and is specific to a not well established library, for which it may not be obvious how to handle this plotting case. – ImportanceOfBeingErnest Apr 10 '17 at 20:01
  • @ImportanceOfBeingErnest thank you very much! i updated the question to hopefully make it a little clearer – Ty Patterson Apr 10 '17 at 20:20
  • Now it's getting confusing. VPython is a 3D plotting library. It can draw objects in 3D space. What you are now asking is not to draw objects but plotting values on axes. – ImportanceOfBeingErnest Apr 10 '17 at 20:35
  • @ImportanceOfBeingErnest i would like to make a grid with 20x20 objects that correspond to the 20x20 points in the array and increase in size in the z direction as the value of the point corresponding to them in the array gets larger – Ty Patterson Apr 10 '17 at 21:46

0 Answers0