|
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 |