示例#1
0
    def test_cylinder(self):
        # When
        c = visual.cylinder(radius=0.5, length=2, pos=(1, 1, 1))

        # Then
        assert_allclose(c.polydata.bounds, (1.0, 3.0, 0.5, 1.5, 0.5, 1.5), rtol=1e-2)

        # When
        c = visual.cylinder(radius=0.5, length=2, x=1.0)

        # Then
        assert_allclose(c.polydata.bounds, (1.0, 3.0, -0.5, 0.5, -0.5, 0.5), rtol=5e-2)
示例#2
0
    def test_cylinder(self):
        # When
        c = visual.cylinder(radius=0.5, length=2, pos=(1, 1, 1))

        # Then
        assert_allclose(c.polydata.bounds, (1.0, 3.0, 0.5, 1.5, 0.5, 1.5),
                        rtol=1e-2)

        # When
        c = visual.cylinder(radius=0.5, length=2, x=1.0)

        # Then
        assert_allclose(c.polydata.bounds, (1.0, 3.0, -0.5, 0.5, -0.5, 0.5),
                        rtol=5e-2)
    def create_unicycle(self):
        visual.set_viewer(self.scene)
        self.wheel_top = visual.box(color = (0.2, 0.5, 0.5), pos = (0, 1.0, 0), length = 1.6, width = 1.6, height = 0.04)
        self.spring = visual.helix(coils = 8, axis = (0.0, 1.0, 0.0), color = (0.8, 0.2, 0.8), pos = (0.14, 1.0, 0), radius = 0.1, length = 0.5)
        self.car = visual.box(color = (0.2, 0.2, 0.8), pos = (0.0, 1.7, 0.0), length = 0.6, height = 0.4, width = 0.6)
        self.dash_top = visual.cylinder(axis = (0.0, -1.0, 0.0), color = (0.8, 0.8, 0.2), pos = (-0.14, 1.7, 0.0), radius = 0.1, length = 0.3)
        self.dash_bottom = visual.cylinder(axis = (0.0, 1.0, 0.0), color = (0.8, 0.8, 0.2), pos = (-0.14, 1.0, 0.0), radius = 0.05, length = 0.6)

        self.scene.camera.azimuth(45)
        self.scene.camera.elevation(20)
 
        self.recompute_char_eq()
        self.update_chq_data()
        
        self.tdata = self.state_buf[:,0]
        self.ydata = self.state_buf[:,1]

        self._run_fired()
def drawSatellite(position,euler):

    # euler angles are in radians
    
    psi, theta, phi = euler
    
    sat = visual.cylinder()
    sat.length = 300
    sat.radius = 300
    sat.x = position[0]
    sat.y = position[1]
    sat.z = position[2]
    
    sat.rotate(degrees(psi)   , [0,0,1] ,position)
    sat.rotate(degrees(theta) , [0,1,0] ,position)
    sat.rotate(degrees(phi)   , [1,0,0] ,position)

    return sat
def drawSatellite(position, euler):

    # euler angles are in radians

    psi, theta, phi = euler

    sat = visual.cylinder()
    sat.length = 300
    sat.radius = 300
    sat.x = position[0]
    sat.y = position[1]
    sat.z = position[2]

    sat.rotate(degrees(psi), [0, 0, 1], position)
    sat.rotate(degrees(theta), [0, 1, 0], position)
    sat.rotate(degrees(phi), [1, 0, 0], position)

    return sat
示例#6
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()
示例#7
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.
示例#8
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()
示例#9
0
文件: gyro2.py 项目: B-Rich/mayavi
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():
示例#10
0
    Animation

"""
# Create a figure
f = mlab.figure(size=(1000, 1000))
# Tell visual to use this as the viewer.
visual.set_viewer(f)
robot_radius = .15
robot_height = robot_radius / 5.0

# Elements in animation
robot_x_axis = (0, 0, 1.0)
robot_x_pos = (x[0, 0, 0], -L / 2., 0)
robot_x = visual.cylinder(pos=robot_x_pos,
                          axis=robot_x_axis,
                          radius=robot_radius,
                          length=robot_height,
                          color=(0.0, 1.0, 0.0))

robot_y_axis = (0, 0, 1.0)
robot_y_pos = (x[0, 1, 0], L / 2., 0)
robot_y = visual.cylinder(pos=robot_y_pos,
                          axis=robot_y_axis,
                          radius=robot_radius,
                          length=robot_height,
                          color=(1.0, 0.0, 0.0))

vtext = tvtk.VectorText()
vtext.text = str(t[0]) + ' s'
text_mapper = tvtk.PolyDataMapper(input=vtext.get_output())
p2 = tvtk.Property(color=(0.3, 0.3, 0.3))