def anim(): 
    #Evolucion de la bola 1
    bola1.t = bola1.t + bola1.dt
    i = bola1.t
    bola1.pos = visual.vector( x1_t[i], y1_t[i], r1 )
    
    #Evolucion de la bola 2
    bola2.t = bola2.t + bola2.dt
    i = bola2.t
    bola2.pos = visual.vector( x2_t[i], y2_t[i], r2 )
    
    #Evolucion de la bola 3
    bola3.t = bola3.t + bola3.dt
    i = bola3.t
    bola3.pos = visual.vector( x3_t[i], y3_t[i], r3 )
Beispiel #2
0
def anim():
    #Evolucion de la bola 1
    bola1.t = bola1.t + bola1.dt
    i = bola1.t
    bola1.pos = visual.vector(x1_t[i], y1_t[i], r1)

    #Evolucion de la bola 2
    bola2.t = bola2.t + bola2.dt
    i = bola2.t
    bola2.pos = visual.vector(x2_t[i], y2_t[i], r2)

    #Evolucion de la bola 3
    bola3.t = bola3.t + bola3.dt
    i = bola3.t
    bola3.pos = visual.vector(x3_t[i], y3_t[i], r3)
Beispiel #3
0
def anim():
    global theta, phidot, alphadot, M, g, r, thetadot, phi, alpha, t
    for step in range(Nsteps):  # multiple calculation steps for accuracy
        # Calculate accelerations of the Lagrangian coordinates:
        atheta = (phidot**2 * sin(theta) * cos(theta) - 2. *
                  (alphadot + phidot * cos(theta)) * phidot * sin(theta) +
                  2. * M * g * r * sin(theta) / I)
        aphi = 2. * thetadot * (alphadot - phidot * cos(theta)) / sin(theta)
        aalpha = phidot * thetadot * sin(theta) - aphi * cos(theta)
        # Update velocities of the Lagrangian coordinates:
        thetadot = thetadot + atheta * dt
        phidot = phidot + aphi * dt
        alphadot = alphadot + aalpha * dt
        # Update Lagrangian coordinates:
        theta = theta + thetadot * dt
        phi = phi + phidot * dt
        alpha = alpha + alphadot * dt

    gyro.axis = vector(
        sin(theta) * sin(phi), cos(theta),
        sin(theta) * cos(phi))
    # Display approximate rotation of rotor and shaft:
    gyro.rotate(axis=gyro.axis, angle=alphadot * dt * Nsteps, origin=gyro.pos)
    trail.append(gyro.pos + gyro.axis * Lshaft)
    t = t + dt * Nsteps
Beispiel #4
0
    def __init__(self,
                 wp_list,
                 np_file='/tmp/magnetic_ground_truth.np',
                 width=800,
                 height=600):
        self.debug = True

        self.width = width
        self.height = height

        self.wp_list = wp_list

        self.f = mlab.figure(size=(self.width, self.height))
        visual.set_viewer(self.f)

        v = mlab.view(135, 180)

        self.balls = []
        self.trajectories = []

        colors = list(RoiSimulator.color_codes)
        color_black = colors.pop(0)
        color_red = colors.pop(0)

        wp_curve = visual.curve(color=color_red,
                                radius=RoiSimulator.curve_radius)
        hist_pos = []

        for i in xrange(len(self.wp_list)):
            ball = visual.sphere(color=color_black,
                                 radius=RoiSimulator.ball_radius)
            wp = self.wp_list[i]

            ball.x = wp[1]
            ball.y = wp[0]
            ball.z = wp[2]

            self.balls.append(ball)

            arr = visual.vector(float(wp[1]), float(wp[0]), float(wp[2]))
            hist_pos.append(arr)

        wp_curve.extend(hist_pos)

        x = np.linspace(0, self.width, 1)
        y = np.linspace(0, self.height, 1)

        z = np.loadtxt(np_file)
        z *= 255.0 / z.max()

        # HARDCODED
        # Todo: REMOVE THIS CODE ON THE FINAL RELEASE
        for xx in xrange(0, 200):
            for yy in xrange(400, 600):
                z[yy][xx] = 0
        mlab.surf(x, y, z)
    def __init__(self, wp_list, np_file='/tmp/magnetic_ground_truth.np', width=800, height=600):
        self.debug = True

        self.width = width
        self.height = height

        self.wp_list = wp_list

        self.f = mlab.figure(size=(self.width, self.height))
        visual.set_viewer(self.f)

        self.balls = []
        self.trajectories = []

        colors = list(RoiSimulator.color_codes)
        color_black = colors.pop(0)
        color_red = colors.pop(0)

        wp_curve = visual.curve(color=color_red, radius=RoiSimulator.curve_radius)
        hist_pos = []

        for i in xrange(len(self.wp_list)):
            ball = visual.sphere(color=color_black, radius=RoiSimulator.ball_radius)
            wp = self.wp_list[i]

            ball.x = wp[1]
            ball.y = wp[0]
            ball.z = wp[2]

            self.balls.append(ball)

            arr = visual.vector(float(wp[1]), float(wp[0]), float(wp[2]))
            hist_pos.append(arr)

        wp_curve.extend(hist_pos)

        x = np.linspace(0, self.width, 1)
        y = np.linspace(0, self.height, 1)

        z = np.loadtxt(np_file)
        z *= 255.0/z.max()
        mlab.surf(x, y, z)
Beispiel #6
0
def anim():
    global theta, phidot, alphadot, M, g, r, thetadot, phi, alpha, t
    for step in range(Nsteps): # multiple calculation steps for accuracy
        # Calculate accelerations of the Lagrangian coordinates:
        atheta = (phidot**2*sin(theta)*cos(theta)
                  -2.*(alphadot+phidot*cos(theta))*phidot*sin(theta)
                  +2.*M*g*r*sin(theta)/I)
        aphi = 2.*thetadot*(alphadot-phidot*cos(theta))/sin(theta)
        aalpha = phidot*thetadot*sin(theta)-aphi*cos(theta)
        # Update velocities of the Lagrangian coordinates:
        thetadot = thetadot+atheta*dt
        phidot = phidot+aphi*dt
        alphadot = alphadot+aalpha*dt
        # Update Lagrangian coordinates:
        theta = theta+thetadot*dt
        phi = phi+phidot*dt
        alpha = alpha+alphadot*dt

    gyro.axis = vector(sin(theta)*sin(phi),cos(theta),sin(theta)*cos(phi))
    # Display approximate rotation of rotor and shaft:
    gyro.rotate(axis = gyro.axis, angle=alphadot*dt*Nsteps, origin = gyro.pos)
    trail.append(gyro.pos + gyro.axis * Lshaft)
    t = t+dt*Nsteps
Beispiel #7
0
def main():
    # Creating parameters for box size
    side = 4.0
    thk = 0.3
    s2 = 2 * side - thk
    s3 = 2 * side + thk
    # Creating the 6 walls
    wallR = box(pos=(side, 0, 0), size=(thk, s3, s2), color=(1, 0, 0))
    wallL = box(pos=(-side, 0, 0), size=(thk, s3, s2), color=(1, 0, 0))
    wallB = box(pos=(0, -side, 0), size=(s3, thk, s3), color=(0, 0, 1))
    wallT = box(pos=(0, side, 0), size=(s3, thk, s3), color=(0, 0, 1))
    wallBK = box(pos=(0, 0, -side), size=(s2, s2, thk), color=(0.7, 0.7, 0.7))
    # Creating the ball
    ball = sphere(radius=0.4, color=(0, 1, 0))
    ball.vector = vector(-0.15, -0.23, 0.27)

    side = side - thk * 0.5 - ball.radius

    ball.t = 0.0
    ball.dt = 0.5

    def anim():
        #Creating the animation function which will be called at
        #uniform timeperiod through the iterate function
        ball.t = ball.t + ball.dt
        ball.pos = ball.pos + ball.vector * ball.dt
        if not (side > ball.x > -side):
            ball.vector.x = -ball.vector.x
        if not (side > ball.y > -side):
            ball.vector.y = -ball.vector.y
        if not (side > ball.z > -side):
            ball.vector.z = -ball.vector.z

    a = iterate(20, anim)
    show()
    return a
Beispiel #8
0
def main():
    # Creating parameters for box size
    side = 4.0
    thk = 0.3
    s2 = 2*side - thk
    s3 = 2*side + thk
    # Creating the 6 walls
    wallR = box( pos = (side, 0, 0), size = (thk, s3, s2), color = (1, 0, 0))
    wallL = box( pos = (-side, 0, 0), size = (thk, s3, s2), color = (1, 0, 0))
    wallB = box( pos = (0, -side, 0), size = (s3, thk, s3), color = (0, 0, 1))
    wallT = box( pos = (0, side, 0), size = (s3, thk, s3), color = (0, 0, 1))
    wallBK = box( pos = (0, 0, -side), size = (s2, s2, thk), color = (0.7,0.7,0.7))
    # Creating the ball
    ball = sphere(radius = 0.4, color = (0, 1, 0))
    ball.vector = vector(-0.15, -0.23, 0.27)

    side = side -thk*0.5 - ball.radius

    ball.t = 0.0
    ball.dt = 0.5

    def anim():
        #Creating the animation function which will be called at
        #uniform timeperiod through the iterate function
        ball.t = ball.t + ball.dt
        ball.pos = ball.pos + ball.vector*ball.dt
        if not (side > ball.x > -side):
            ball.vector.x = -ball.vector.x
        if not (side > ball.y > -side):
            ball.vector.y = -ball.vector.y
        if not (side > ball.z > -side):
            ball.vector.z =  -ball.vector.z

    a = iterate(20, anim)
    show()
    return a
Beispiel #9
0
    def update_pos(self):
        self.print_message("Updating pos")

        if self.status == RobotBall.STATUS_END or self.status == RobotBall.STATUS_DAMAGED:
            self.print_message("End status!")
            return

        if self.battery <= 0:
            self.status = RobotBall.STATUS_END
            self.print_message("No battery!")
            return

        if self.status == RobotBall.STATUS_GOING_HOME or self.status == RobotBall.STATUS_ENDING:
            curr_wp = self.home_route[0]
            self.print_message("Going to home!")
        elif self.status == RobotBall.STATUS_GOING_TO_NEXT_HEX:
            curr_wp = self.next_hexagon_route[0]
            self.print_message("Going to next hexagon!")
        elif self.status == RobotBall.STATUS_GOING_TO_ROUTE:
            curr_wp = self.return_to_route[0]
            self.print_message("Going to route!")
        else:
            self.print_message(
                "Normal WP h_index {0} of {1} wp_index {2} of {3}".format(
                    self.hex_index, len(self.hex_internal_list), self.wp_index,
                    len(self.hex_internal_list[self.hex_index])))
            curr_wp = self.hex_internal_list[self.hex_index][self.wp_index]
            if self.check_need_to_go_home():
                self.print_message("Need to go home!")
                return

        ball_pos = self.ball.pos.tolist()

        if self.debug:
            self.print_message("Current wp: {0} {1}".format(
                self.wp_index, curr_wp))
            self.print_message("Ball pos: {0}".format(ball_pos))
            self.print_message("Current hexagon: {0} of {1}".format(
                self.hex_index, len(self.hex_internal_list)))

        py, px, pz = curr_wp
        bx, by, bz = ball_pos

        if self.last_position != ball_pos:
            arr = visual.vector(float(bx), float(by), float(bz))
            self.history.append(arr)

            if len(self.history) > 2:
                self.hist_curve.extend(self.history)
                self.history[:] = []

        self.last_position = ball_pos

        dx = px - bx
        dy = py - by
        dz = pz - bz

        if self.debug:
            self.print_message("dx:{0} dy:{1} dz:{2}".format(dx, dy, dz))

        if abs(dx) > self.max_delta or abs(dy) > self.max_delta or abs(
                dz) > self.max_delta:
            if self.movement_mode == 0:
                err = self.step_p

                self.ball.x += dx * err
                self.ball.y += dy * err
                self.ball.z += dz * err
            else:
                err = self.step_p
                lim = 10

                ddx = dx * err
                ddy = dy * err
                ddz = dz * err

                if abs(ddx) > lim:
                    if cmp(ddx, 0) < 0:
                        self.ball.x += (lim * -1)
                    else:
                        self.ball.x += lim
                else:
                    self.ball.x += ddx

                if abs(ddy) > lim:
                    if cmp(ddy, 0) < 0:
                        self.ball.y += (lim * -1)
                    else:
                        self.ball.y += lim
                else:
                    self.ball.y += ddy

                if abs(ddz) > lim:
                    if cmp(ddz, 0) < 0:
                        self.ball.z += (lim * -1)
                    else:
                        self.ball.z += lim
                else:
                    self.ball.z += ddz
        else:
            if self.status == RobotBall.STATUS_GOING_HOME:
                if len(self.home_route) > 1:
                    self.home_route.pop(0)
                else:
                    self.status = RobotBall.STATUS_GOING_TO_ROUTE
                    self.battery = self.base_battery
                    self.print_message("Battery reloaded: {0}".format(
                        self.battery))
            elif self.status == RobotBall.STATUS_GOING_TO_ROUTE:
                if len(self.return_to_route) > 1:
                    self.return_to_route.pop(0)
                else:
                    self.status = RobotBall.STATUS_START
                    self.print_message("Starting route again...")
            elif self.status == RobotBall.STATUS_GOING_TO_NEXT_HEX:
                if len(self.next_hexagon_route) > 1:
                    self.next_hexagon_route.pop(0)
                else:
                    self.status = RobotBall.STATUS_START
                    self.print_message("Starting new hex...")
            elif self.status == RobotBall.STATUS_ENDING:
                if len(self.home_route) > 1:
                    self.home_route.pop(0)
                else:
                    self.status = RobotBall.STATUS_END
                    self.print_message("Ended!")
            else:
                self.print_message("WP reached")
                if self.wp_index + 1 < len(
                        self.hex_internal_list[self.hex_index]):
                    self.print_message("Added one to index {0} {1}".format(
                        self.wp_index + 1,
                        len(self.hex_internal_list[self.hex_index])))
                    self.wp_index += 1
                else:
                    self.wp_index = 0
                    if self.hex_index + 1 < len(self.hex_internal_list):
                        self.hex_index += 1

                        self.print_message(
                            "Increment index hexagon {0} of {1}".format(
                                self.hex_index,
                                len(self.hex_internal_list) - 1))

                        self.status = RobotBall.STATUS_GOING_TO_NEXT_HEX
                        next_wp = self.hex_internal_list[self.hex_index][
                            self.wp_index]
                        next_hex_route = math_helper.get_line_points(curr_wp,
                                                                     next_wp,
                                                                     step=20)
                        if len(next_hex_route) > 0:
                            go_hex_route = math_helper.get_3d_coverage_points(
                                next_hex_route,
                                self.height,
                                self.np_file,
                                np_mat=self.np_mat)
                            self.next_hexagon_route = go_hex_route
                        else:
                            self.next_hexagon_route = [next_wp]
                        self.print_message("Hexagon route: {0}".format(
                            self.next_hexagon_route))
                    else:
                        self.print_message("Ending")
                        self.hex_index = 0
                        self.status = RobotBall.STATUS_END

        battery_spent = distance.euclidean(self.last_position,
                                           self.ball.pos.tolist())

        # self.print_message("Compare pos: {0} of {1} is {2}".format(
        #                     self.last_position, self.ball.pos.tolist(), battery_spent))

        self.battery -= battery_spent
        self.print_message("Battery level {0} of {1}".format(
            self.battery, self.base_battery))
        pass
Beispiel #10
0
from tvtk.tools.visual import curve, box, vector, show
from numpy import arange, array

lorenz = curve(color=(1, 1, 1), radius=0.3)

# Draw grid
for x in xrange(0, 51, 10):
    curve(points=[[x, 0, -25], [x, 0, 25]], color=(0, 0.5, 0), radius=0.3)
    box(pos=(x, 0, 0), axis=(0, 0, 50), height=0.4, width=0.4, length=50)

for z in xrange(-25, 26, 10):
    curve(points=[[0, 0, z], [50, 0, z]], color=(0, 0.5, 0), radius=0.3)
    box(pos=(25, 0, z), axis=(50, 0, 0), height=0.4, width=0.4, length=50)

dt = 0.01
y = vector(35.0, -10.0, -7.0)

pts = []
for i in xrange(2000):
    # Integrate a funny differential equation
    dydt = vector(-8.0 / 3 * y[0] + y[1] * y[2], -10 * y[1] + 10 * y[2],
                  -y[1] * y[0] + 28 * y[1] - y[2])
    y = y + dydt * dt

    pts.append(y)
    if len(pts) > 20:
        lorenz.extend(pts)
        pts[:] = []

show()
Beispiel #11
0
# The Lagrangian variables are polar angle theta,
# azimuthal angle phi, and spin angle alpha.

Lshaft = 1.  # length of gyroscope shaft
Rshaft = 0.03  # radius of gyroscope shaft
M = 1.  # mass of gyroscope (massless shaft)
Rrotor = 0.4  # radius of gyroscope rotor
Drotor = 0.1  # thickness of gyroscope rotor
Dsquare = 1.4 * Drotor  # thickness of square that turns with rotor
I = 0.5 * M * Rrotor**2.  # moment of inertia of gyroscope
hpedestal = Lshaft  # height of pedestal
wpedestal = 0.1  # width of pedestal
tbase = 0.05  # thickness of base
wbase = 3. * wpedestal  # width of base
g = 9.8
Fgrav = vector(0, -M * g, 0)
top = vector(0, 0, 0)  # top of pedestal

theta = pi / 3.  # initial polar angle of shaft (from vertical)
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,
Beispiel #12
0
from math import sqrt

from tvtk.tools.visual import sphere, iterate, show, vector, curve

#Creating the actors for the scene
giant = sphere(pos=(-1.0e11, 0, 0),
               radius=2e10,
               color=(1, 0, 0),
               mass=2e30)

dwarf = sphere(pos=(1.5e11, 0, 0),
               radius=1e10,
               color=(1, 1, 0),
               mass=1e30)

giant.p = vector(0, 0, -1e4) * giant.mass
dwarf.p = -1*giant.p

# creating the curve which will trace the paths of actors
for a in [giant, dwarf]:
    a.orbit = curve(radius=2e9, color=a.color)

dt = 86400

def anim():
    #Creating the animation function which will be called at
    #uniform timeperiod through the iterate function
    dist = dwarf.pos - giant.pos
    force = 6.7e-11 * giant.mass * dwarf.mass * \
        dist/(sqrt(dist[0]**2 + dist[1]**2 + dist[2]**2))**3
    giant.p = giant.p + force*dt
Beispiel #13
0
L2 = 1.0  # physical length of lower bar
L2display = L2 + d / 2.  # show lower bar a bit longer than physical, to overlap axle
# Coefficients used in Lagrangian calculation
A = (1. / 4.) * M1 * L1**2 + (1. / 12.) * M1 * L1**2 + M2 * L1**2
B = (1. / 2.) * M2 * L1 * L2
C = g * L1 * (M1 / 2. + M2)
D = M2 * L1 * L2 / 2.
E = (1. / 12.) * M2 * L2**2 + (1. / 4.) * M2 * L2**2
F = g * L2 * M2 / 2.

hpedestal = 1.3 * (L1 + L2)  # height of pedestal
wpedestal = 0.1  # width of pedestal
tbase = 0.05  # thickness of base
wbase = 8. * gap  # width of base
offset = 2. * gap  # from center of pedestal to center of U-shaped upper assembly
top = vector(0, 0, 0)  # top of inner bar of U-shaped upper assembly

theta1 = 1.3 * pi / 2.  # initial upper angle (from vertical)
theta1dot = 0  # initial rate of change of theta1
theta2 = 0  # initial lower angle (from vertical)
theta2dot = 0  # initial rate of change of theta2

pedestal = box(pos=(top - vector(0, hpedestal / 2.0, offset)),
               size=(wpedestal, 1.1 * hpedestal, wpedestal),
               color=(0.4, 0.4, 0.5))

base = box(pos=(top - vector(0, hpedestal + tbase / 2.0, offset)),
           size=(wbase, tbase, wbase),
           color=(0.4, 0.4, 0.5))

bar1 = box(pos=(L1display / 2.0 - d / 2.0, 0, -(gap + d) / 2.0),
Beispiel #14
0
    def anim(self):
        end_counter = 0

        for i in xrange(len(self.balls)):
            wp_index = self.index_list[i]
            ball = self.balls[i]

            curr_wp = list(self.wp_list[i][wp_index])
            ball_pos = ball.pos.tolist()
            last_pos = self.last_positions[i]

            if self.debug:
                print "Ball:", i
                print "Current waypoint index:", wp_index, curr_wp
                print "Ball position:", ball_pos

            px, py, pz = curr_wp
            bx, by, bz = ball_pos

            if last_pos != ball_pos:
                arr = visual.vector(float(bx), float(by), float(bz))
                self.history[i].append(arr)

                if len(self.history[i]) > 10:
                    self.trajectories[i].extend(self.history[i])
                    self.history[i][:] = []

            self.last_positions[i] = ball_pos

            dx = px - bx
            dy = py - by
            dz = pz - bz

            if self.debug:
                print "dx:", '{0:.3g}'.format(dx), "dy:", '{0:.3g}'.format(
                    dy), "dz:", '{0:.3g}'.format(dz)

            if abs(dx) > 0.2 or abs(dy) > 0.2 or abs(dz) > 0.2:
                if self.movement_mode == 0:
                    err = 0.1

                    ball.x += dx * err
                    ball.y += dy * err
                    ball.z += dz * err

                else:
                    err = 0.06
                    lim = 1.5

                    ddx = dx * err
                    ddy = dy * err
                    ddz = dz * err

                    if abs(ddx) > lim:
                        if cmp(ddx, 0) < 0:
                            ball.x += (lim * -1)
                        else:
                            ball.x += lim
                    else:
                        ball.x += ddx

                    if abs(ddy) > lim:
                        if cmp(ddy, 0) < 0:
                            ball.y += (lim * -1)
                        else:
                            ball.y += lim
                    else:
                        ball.y += ddy

                    if abs(ddz) > lim:
                        if cmp(ddz, 0) < 0:
                            ball.z += (lim * -1)
                        else:
                            ball.z += lim
                    else:
                        ball.z += ddz

            else:
                if self.debug:
                    print "Increment index (", wp_index, 'of', len(
                        self.wp_list[i]), ')'
                if wp_index + 1 < len(self.wp_list[i]):
                    self.index_list[i] += 1
                else:
                    print 'Ball ', i, 'ended...'
                    end_counter += 1
            pass

            print "\n"

        if end_counter >= len(self.balls):
            print "Exiting path simulation..."
            mlab.close(all=True)
Beispiel #15
0
from tvtk.tools.visual import curve, box, vector, show
from numpy import arange, array

lorenz = curve( color = (1,1,1), radius=0.3 )

# Draw grid
for x in xrange(0,51,10):
    curve(points = [[x,0,-25],[x,0,25]], color = (0,0.5,0), radius = 0.3 )
    box(pos=(x,0,0), axis=(0,0,50), height=0.4, width=0.4, length = 50)

for z in xrange(-25,26,10):
    curve(points = [[0,0,z], [50,0,z]] , color = (0,0.5,0), radius = 0.3 )
    box(pos=(25,0,z), axis=(50,0,0), height=0.4, width=0.4, length = 50)

dt = 0.01
y = vector(35.0, -10.0, -7.0)

pts = []
for i in xrange(2000):
    # Integrate a funny differential equation
    dydt = vector(      -8.0/3*y[0] + y[1]*y[2],
                          - 10*y[1] +   10*y[2],
                   - y[1]*y[0] + 28*y[1] - y[2])
    y = y + dydt * dt

    pts.append(y)
    if len(pts) > 20:
        lorenz.extend(pts)
        pts[:] = []

show()
Beispiel #16
0
# The Lagrangian variables are polar angle theta,
# azimuthal angle phi, and spin angle alpha.

Lshaft = 1. # length of gyroscope shaft
Rshaft = 0.03 # radius of gyroscope shaft
M = 1. # mass of gyroscope (massless shaft)
Rrotor = 0.4 # radius of gyroscope rotor
Drotor = 0.1 # thickness of gyroscope rotor
Dsquare = 1.4*Drotor # thickness of square that turns with rotor
I = 0.5*M*Rrotor**2. # moment of inertia of gyroscope
hpedestal = Lshaft # height of pedestal
wpedestal = 0.1 # width of pedestal
tbase = 0.05 # thickness of base
wbase = 3.*wpedestal # width of base
g = 9.8
Fgrav = vector(0,-M*g,0)
top = vector(0,0,0) # top of pedestal

theta = pi/3. # initial polar angle of shaft (from vertical)
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),
Beispiel #17
0
#!/usr/bin/env python
"""A simple example demonstrating the creation of actors and animating
the in a scene using visual modeule."""
# Author: Raashid Baig <*****@*****.**>
# License: BSD Style.

from math import sqrt

from tvtk.tools.visual import sphere, iterate, show, vector, curve

#Creating the actors for the scene
giant = sphere(pos=(-1.0e11, 0, 0), radius=2e10, color=(1, 0, 0), mass=2e30)

dwarf = sphere(pos=(1.5e11, 0, 0), radius=1e10, color=(1, 1, 0), mass=1e30)

giant.p = vector(0, 0, -1e4) * giant.mass
dwarf.p = -1 * giant.p

# creating the curve which will trace the paths of actors
for a in [giant, dwarf]:
    a.orbit = curve(radius=2e9, color=a.color)

dt = 86400


def anim():
    #Creating the animation function which will be called at
    #uniform timeperiod through the iterate function
    dist = dwarf.pos - giant.pos
    force = 6.7e-11 * giant.mass * dwarf.mass * \
        dist/(sqrt(dist[0]**2 + dist[1]**2 + dist[2]**2))**3
Beispiel #18
0
L2 = 1.0 # physical length of lower bar
L2display = L2+d/2. # show lower bar a bit longer than physical, to overlap axle
# Coefficients used in Lagrangian calculation
A = (1./4.)*M1*L1**2+(1./12.)*M1*L1**2+M2*L1**2
B = (1./2.)*M2*L1*L2
C = g*L1*(M1/2.+M2)
D = M2*L1*L2/2.
E = (1./12.)*M2*L2**2+(1./4.)*M2*L2**2
F = g*L2*M2/2.

hpedestal = 1.3*(L1+L2) # height of pedestal
wpedestal = 0.1 # width of pedestal
tbase = 0.05 # thickness of base
wbase = 8.*gap # width of base
offset = 2.*gap # from center of pedestal to center of U-shaped upper assembly
top = vector(0,0,0) # top of inner bar of U-shaped upper assembly

theta1 = 1.3*pi/2. # initial upper angle (from vertical)
theta1dot = 0 # initial rate of change of theta1
theta2 = 0 # initial lower angle (from vertical)
theta2dot = 0 # initial rate of change of theta2

pedestal = box(pos = (top - vector(0, hpedestal/2.0, offset)),size = (wpedestal, 1.1*hpedestal, wpedestal), color = (0.4,0.4,0.5))

base = box(pos = (top - vector(0,hpedestal + tbase/2.0, offset)),size=(wbase, tbase, wbase),color = (0.4,0.4,0.5))

bar1 = box(pos=(L1display/2.0 - d/2.0, 0, -(gap+d)/2.0), size=(L1display, d, d), color=(1,0,0))
bar1b = box(pos=(L1display/2.0 - d/2.0, 0, (gap+d)/2.0), size=(L1display, d, d), color=(1,0,0))

frame1 = frame(bar1, bar1b)
frame1.pos = (0.0, 0.0, 0.0)
Beispiel #19
0
#!/usr/bin/env python

# Author: Raashid Baig <*****@*****.**>
# License: BSD Style.

# Gyroscope hanging from a spring
from math import atan, cos, sin, pi

from tvtk.tools.visual import vector, MVector, Box, Helix, Frame, \
    Cylinder, curve, color, iterate, show


top = vector(0,1.,0) # where top of spring is held
ks = 100. # spring stiffness
Lspring = 1. # unstretched length of spring
Rspring = 0.03 # radius of spring
Dspring = 0.03 # thickness of spring wire
Lshaft = 1. # length of gyroscope shaft
Rshaft = 0.03 # radius of gyroscope shaft
M = 1. # mass of gyroscope (massless shaft)
Rrotor = 0.4 # radius of gyroscope rotor
Drotor = 0.1 # thickness of gyroscope rotor
Dsquare = 1.4*Drotor # thickness of square that turns with rotor
I = 0.5*M*Rrotor**2. # moment of inertia of gyroscope
omega = 40.0 # angular velocity of rotor along axis
g = 9.8
Fgrav = MVector(0,-M*g,0)
precession = M*g*(Lshaft/2.)/(I*abs(omega)) # exact precession angular velocity
phi = atan(precession**2*(Lshaft/2.)/g) # approximate angle of spring to vertical
s = M*g/(ks*cos(phi)) # approximate stretch of spring
# Refine estimate of angle of spring to vertical: