From: Joe H. <hea...@gm...> - 2011-06-08 20:22:31
|
I want to create some VPython simulations related to Gauss's law, flux, and solid angle. I want to get across the point that any arbitrarily shaped surface can, mathematically, be morphed into a sphere using the concept of solid angle. Is there a way to make an arbitrarily shaped patch of area morph SMOOTHLY into a square in VPython? Below is the code I have so far. It works, but it's not as smooth as I'd like it to be. from visual import * # a field arrow E = vector(1,-0.5,0) Earrow = arrow(pos=vector(0,0,0),axis=E,shaftwidth=0.01,color=color.red) Ehat = norm(E) # a patch of area # include option for circular patches direction = vector(1,1,1) patch = box(pos=(0,0,0),axis=direction,length=0.02,width=0.5,height=0.5) # patch morphing is smoother if height > width # patch's initial area patch.height0 = patch.height patch.area = patch.height*patch.width print ("initial area ", patch.area) # a unit normal to patch nhat = norm(patch.axis) nhatarrow = arrow(pos=Earrow.pos,axis=nhat,shaftwidth=0.01,color=color.green) scene.forward = -nhat # get angle between the two vectors newtheta = acos(dot(Ehat,nhat)) # check for newtheta = 0 # check for newtheta = pi print ("angle ",newtheta*180.0/pi) print ("predicted perp area ", patch.area * cos(newtheta)) # get the new rotation axis newaxis = cross(Ehat,nhat) # rotation animation scene.mouse.getclick() print ("rotating...") dtheta=0.001 theta=0.0 while theta < newtheta: rate(1000) nhatarrow.rotate(angle=-dtheta,axis=newaxis) patch.rotate(angle=-dtheta,axis=newaxis) patch.height = patch.height0*cos(abs(theta)) theta += dtheta patch.area = patch.area * cos(newtheta) patch.width = sqrt(patch.area) patch.height = patch.width print ("actual perp area ", patch.height*patch.width) print ("patch axis ",norm(patch.axis)) print ("field axis ",norm(Earrow.axis)) Joe Heafner Sent from my iPad |