Re: Need coding suggestions

"K.-Michael Aye" <[email protected]>
Newsgroups gmane.comp.python.visualpython.user
Message-ID <71613503943703914@unknownmsgid>
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 <[email protected]> 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
Visualpython-users-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
https://lists.sourceforge.net/lists/listinfo/visualpython-users

------------------------------------------------------------------------------
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
Visualpython-users-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
https://lists.sourceforge.net/lists/listinfo/visualpython-users
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.