Пример #1
0
    box (pos = (xx,yy,zz), length=x, height=y, width=z,
         color=(red,green,blue))
    
def wirecube(s):
    c = curve(color = (1,1,1), radius=1)
    pts = [(-s, -s, -s),(-s, -s, s), (-s, s, s),
           (-s, s, -s), (-s, -s, -s), (s, -s, -s),
           (s, s, -s), (-s, s, -s), (s, s, -s),
           (s, s, s), (-s, s, s), (s, s, s),
           (s, -s, s), (-s, -s, s), (s, -s, s),(s, -s, -s)]
    for pt in pts:
        c.append(pt)

side = 150.0
cube = box(size = (side,side,side), representation = 'w' )
i = 0
while i < 100:
    random_box()
    i = i + 1

arrow(axis=(0,12,0), radius_shaft=3.5, color = (1,0,0))

ball = sphere(pos=(-side/2.,-side/2.,-side/2.),color=(1,1,0),radius=3)
disk = cylinder(pos=(side/2.,side/2.,-side/2.),color=(.3,.3,1),axis=(1,1,0),radius=5)
xx = arange(0,4*pi,pi/10.)
spring=curve(color=(1,.7,.1), radius=0.4)
for y in xx:
    spring.append([20+cos(2*y), y/2.-30, -20+sin(2*y)+30])

show()
Пример #2
0
floor = V.box(pos=(D/2.,0,0), length=D, height=0.5, width=D)

# Use a cone for our 'arrow'
#arrow = V.cone(pos=(0,0,0), radius=0.9, axis=sight,color=V.color.red)
arrow = V.cone(pos=(0,0,0), radius=0.9, axis=sight)
arrow.velocity = v0*sight

# The target is a sphere
#target = V.sphere(pos=(D,H,0), radius=1, color=V.color.yellow)
target = V.sphere(pos=(D,H,0), radius=1)
target.velocity = V.vector(0,0,0)

# The 'dart gun' is just a cylinder.
gun = V.cylinder(pos=(0,0,0), axis=gun_len*sight, radius=1,
#                 color = V.color.green)
                 )

# Run simulation

print 'Starting simulation...'

# Put a little delay to give all the OpenGL stuff time to initialize nicely.
#time.sleep(1)

while (arrow.y >= 0 and target.y >=0) and \
          mag(arrow.pos-target.pos) > impact_distance:

    #V.rate(75)

    for obj in (arrow,target):
Пример #3
0
# Comment in following line to get pure precession
##phidot = (-alphadot+sqrt(alphadot**2+2*M*g*r*cos(theta)/I))/cos(theta)

pedestal = box(pos=top - vector(0, hpedestal / 2., 0),
               height=hpedestal,
               length=wpedestal,
               width=wpedestal,
               color=(0.4, 0.4, 0.5))
base = box(pos=top - vector(0, hpedestal + tbase / 2., 0),
           height=tbase,
           length=wbase,
           width=wbase,
           color=pedestal.color)

shaft = cylinder(axis=(Lshaft, 0, 0),
                 length=Lshaft,
                 radius=Rshaft,
                 color=(0, 1, 0))
rotor = cylinder(pos=(Lshaft / 2 - Drotor / 2, 0, 0),
                 axis=(Drotor, 0, 0),
                 length=Drotor,
                 radius=Rrotor,
                 color=(1, 0, 0))

gyro = frame(shaft, rotor)
gyro.axis = (sin(theta) * sin(phi), cos(theta), sin(theta) * cos(phi))

trail = curve(radius=Rshaft / 8., color=(1, 1, 0))

r = Lshaft / 2.
dt = 0.0001
t = 0.
Пример #4
0
    pts = [(-s, -s, -s), (-s, -s, s), (-s, s, s), (-s, s, -s), (-s, -s, -s),
           (s, -s, -s), (s, s, -s), (-s, s, -s), (s, s, -s), (s, s, s),
           (-s, s, s), (s, s, s), (s, -s, s), (-s, -s, s), (s, -s, s),
           (s, -s, -s)]
    for pt in pts:
        c.append(pt)


side = 150.0
cube = box(size=(side, side, side), representation='w')
i = 0
while i < 100:
    random_box()
    i = i + 1

arrow(axis=(0, 12, 0), radius_shaft=3.5, color=(1, 0, 0))

ball = sphere(pos=(-side / 2., -side / 2., -side / 2.),
              color=(1, 1, 0),
              radius=3)
disk = cylinder(pos=(side / 2., side / 2., -side / 2.),
                color=(.3, .3, 1),
                axis=(1, 1, 0),
                radius=5)
xx = arange(0, 4 * pi, pi / 10.)
spring = curve(color=(1, .7, .1), radius=0.4)
for y in xx:
    spring.append([20 + cos(2 * y), y / 2. - 30, -20 + sin(2 * y) + 30])

show()
Пример #5
0
thetadot = 0 # initial rate of change of polar angle
alpha = 0 # initial spin angle
alphadot = 15 # initial rate of change of spin angle (spin ang. velocity)
phi = -pi/2. # initial azimuthal angle
phidot = 0 # initial rate of change of azimuthal angle
# Comment in following line to get pure precession
##phidot = (-alphadot+sqrt(alphadot**2+2*M*g*r*cos(theta)/I))/cos(theta)

pedestal = box(pos=top-vector(0,hpedestal/2.,0),
                 height=hpedestal, length=wpedestal, width=wpedestal,
                 color=(0.4,0.4,0.5))
base = box(pos=top-vector(0,hpedestal+tbase/2.,0),
                 height=tbase, length=wbase, width=wbase,
                 color=pedestal.color)

shaft = cylinder(axis=(Lshaft,0,0), length = Lshaft,
                 radius=Rshaft, color=(0,1,0))
rotor = cylinder(pos=(Lshaft/2 - Drotor/2, 0, 0),
                 axis=(Drotor, 0, 0), length = Drotor,
                 radius=Rrotor, color=(1,0,0))

gyro = frame(shaft, rotor)
gyro.axis = (sin(theta)*sin(phi),cos(theta),sin(theta)*cos(phi))

trail = curve(radius=Rshaft/8., color=(1,1,0))

r = Lshaft/2.
dt = 0.0001
t = 0.
Nsteps = 20 # number of calculational steps between graphics updates

def anim():