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 |
From: K.-Michael A. <kmi...@gm...> - 2011-06-08 20:51:14
|
Maybe this is a use case for the PyGeo package that uses Vpython, I believe? Michael On 08.06.2011, at 22:23, Joe Heafner <hea...@gm...> wrote: 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 ------------------------------------------------------------------------------ EditLive Enterprise is the world's most technically advanced content authoring tool. Experience the power of Track Changes, Inline Image Editing and ensure content is compliant with Accessibility Checking. http://p.sf.net/sfu/ephox-dev2dev _______________________________________________ Visualpython-users mailing list Vis...@li... https://lists.sourceforge.net/lists/listinfo/visualpython-users |
From: Bruce S. <Bru...@nc...> - 2011-06-09 04:03:06
|
Not sure what you're concerned about. It looks smooth to me until the very end, where there is an abrupt change in the shape of the rectangle. Also, something like rate(200) gives a better sense of the morphing than rate(1000), in my opinion. Bruce On Wed, Jun 8, 2011 at 2:22 PM, Joe Heafner <hea...@gm...> wrote: > 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: Kadir H. <kha...@ya...> - 2011-06-09 07:18:50
|
You can use the new EXTRUSION object to start with any arbitrary shaped polygon in 2D. I do not know about the solid angles, but if it is able to reduce the number of "sides" of the polygon down to 4 with some algorithm, then you will end up with a 4-sided polygon, or a square if all with right angles. Kadir ________________________________ From: Joe Heafner <hea...@gm...> To: Visualpython-users <vis...@li...> Sent: Wed, June 8, 2011 11:22:23 PM Subject: [Visualpython-users] Need coding suggestions 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 HeafnerSent from my iPad |