Ejemplo n.º 1
0
def Ch3_Prob5(time):
	base = 57.9#base for distance from the sun. (x = 1 means 57.9 km )
	rad_base = 10*2440#base for the radius of the planets size of each
	#Per_base = 88# base for the period
	
	sun = sphere(pos = [0,0,0], radius = .5)
	mercu = sphere(pos = [(57.90/base), 0, 0], radius = (2440.0/rad_base))
	venus = sphere(pos = [(108.2/base), 0, 0], radius = (6052.0/rad_base))
	earth = sphere(pos = [(149.6/base), 0, 0], radius = (6371.0/rad_base))
	marss = sphere(pos = [(227.6/base), 0, 0], radius = (3386.0/rad_base))
	
	#frequencies
	Fmerc = 2*pi/88
	Fvenu = 2*pi/224.7
	Feart = 2*pi/365.3
	Fmars = 2*pi/687.0
	
	#colors
	sun.color = color.yellow
	mercu.color = color.gray(0.5)
	earth.color = color.blue
	marss.color = color.red
	
	for t in arange(0,time,0.01):
		#print t
		rate(100)
		mercu.pos = [(57.90/base)*cos(Fmerc*t), (57.90/base)*sin(Fmerc*t), 0]
		venus.pos = [(108.2/base)*cos(Fvenu*t), (108.2/base)*sin(Fvenu*t), 0]
		earth.pos = [(149.6/base)*cos(Feart*t), (149.6/base)*sin(Feart*t), 0]
		marss.pos = [(227.6/base)*cos(Fmars*t), (227.6/base)*sin(Fmars*t), 0]
	return 'done'
Ejemplo n.º 2
0
def main():
    if len(argv) < 3:
        raise Exception('>>> ERROR! Please supply values for black hole mass [>= 1.0] and spin [0.0 - 1.0] <<<')
    m = float(argv[1])
    a = float(argv[2])
    horizon = m * (1.0 + sqrt(1.0 - a * a))
    cauchy = m * (1.0 - sqrt(1.0 - a * a))
    #  set up the scene
    scene.center = (0.0, 0.0, 0.0)
    scene.width = scene.height = 1024
    scene.range = (20.0, 20.0, 20.0)
    inner = 2.0 * sqrt(cauchy**2 + a**2)
    ellipsoid(pos = scene.center, length = inner, height = inner, width = 2.0 * cauchy, color = color.blue, opacity = 0.4)  # Inner Horizon
    outer = 2.0 * sqrt(horizon**2 + a**2)
    ellipsoid(pos = scene.center, length = outer, height = outer, width = 2.0 * horizon, color = color.blue, opacity = 0.3)  # Outer Horizon
    ergo = 2.0 * sqrt(4.0 + a**2)
    ellipsoid(pos = scene.center, length = ergo, height = ergo, width = 2.0 * horizon, color = color.gray(0.7), opacity = 0.2)  # Ergosphere
    if fabs(a) > 0.0:
        ring(pos=scene.center, axis=(0, 0, 1), radius = a, color = color.white, thickness=0.01)  # Singularity
    else:
        sphere(pos=scene.center, radius = 0.05, color = color.white)  # Singularity
    ring(pos=scene.center, axis=(0, 0, 1), radius = sqrt(isco(a)**2 + a**2), color = color.magenta, thickness=0.01)  # ISCO
    curve(pos=[(0.0, 0.0, -15.0), (0.0, 0.0, 15.0)], color = color.gray(0.7))
    #cone(pos=(0,0,12), axis=(0,0,-12), radius=12.0 * tan(0.15 * pi), opacity=0.2)
    #cone(pos=(0,0,-12), axis=(0,0,12), radius=12.0 * tan(0.15 * pi), opacity=0.2)
    #sphere(pos=(0,0,0), radius=3.0, opacity=0.2)
    #sphere(pos=(0,0,0), radius=12.0, opacity=0.1)
    # animate!
    ball = sphere()  # Particle
    counter = 0
    dataLine = stdin.readline()
    while dataLine:  # build raw data arrays
        rate(60)
        if counter % 1000 == 0:
            ball.visible = False
            ball = sphere(radius = 0.2)  # Particle
            ball.trail = curve(size = 1)  #  trail
        data = loads(dataLine)
        e = float(data['v4e'])
        if e < -120.0:
            ball.color = color.green
        elif e < -90.0:
            ball.color = color.cyan
        elif e < -60.0:
            ball.color = color.yellow
        elif e < -30.0:
            ball.color = color.orange
        else:
            ball.color = color.red
        r = float(data['r'])
        th = float(data['th'])
        ph = float(data['ph'])
        ra = sqrt(r**2 + a**2)
        sth = sin(th)
        ball.pos = (ra * sth * cos(ph), ra * sth * sin(ph), r * cos(th))
        ball.trail.append(pos = ball.pos, color = ball.color)
        counter += 1
        dataLine = stdin.readline()
Ejemplo n.º 3
0
def gettile(cpos=None):
    if cpos is None:
        cpos = visual.vector((0, 0, 0))
    elif type(cpos) == tuple:
        cpos = visual.vector(cpos)

    dip_sep = 1.10  # dipole separations in meters
    xoffsets = [0.0] * 16  # offsets of the dipoles in the W-E 'x' direction
    yoffsets = [0.0] * 16  # offsets of the dipoles in the S-N 'y' direction
    xoffsets[0] = -1.5 * dip_sep
    xoffsets[1] = -0.5 * dip_sep
    xoffsets[2] = 0.5 * dip_sep
    xoffsets[3] = 1.5 * dip_sep
    xoffsets[4] = -1.5 * dip_sep
    xoffsets[5] = -0.5 * dip_sep
    xoffsets[6] = 0.5 * dip_sep
    xoffsets[7] = 1.5 * dip_sep
    xoffsets[8] = -1.5 * dip_sep
    xoffsets[9] = -0.5 * dip_sep
    xoffsets[10] = 0.5 * dip_sep
    xoffsets[11] = 1.5 * dip_sep
    xoffsets[12] = -1.5 * dip_sep
    xoffsets[13] = -0.5 * dip_sep
    xoffsets[14] = 0.5 * dip_sep
    xoffsets[15] = 1.5 * dip_sep

    yoffsets[0] = 1.5 * dip_sep
    yoffsets[1] = 1.5 * dip_sep
    yoffsets[2] = 1.5 * dip_sep
    yoffsets[3] = 1.5 * dip_sep
    yoffsets[4] = 0.5 * dip_sep
    yoffsets[5] = 0.5 * dip_sep
    yoffsets[6] = 0.5 * dip_sep
    yoffsets[7] = 0.5 * dip_sep
    yoffsets[8] = -0.5 * dip_sep
    yoffsets[9] = -0.5 * dip_sep
    yoffsets[10] = -0.5 * dip_sep
    yoffsets[11] = -0.5 * dip_sep
    yoffsets[12] = -1.5 * dip_sep
    yoffsets[13] = -1.5 * dip_sep
    yoffsets[14] = -1.5 * dip_sep
    yoffsets[15] = -1.5 * dip_sep

    gp = visual.box(pos=visual.vector(0, 0, 0) + cpos,
                    axis=(0, 0, 1),
                    height=5.0,
                    width=5.0,
                    length=0.05,
                    color=color.gray(0.5),
                    visible=False)
    olist = [gp]
    for i in range(16):
        dlist = getdipole(cpos=visual.vector(xoffsets[i], yoffsets[i], 0) +
                          cpos)
        olist += dlist
    return olist
Ejemplo n.º 4
0
    def __init__(self):
        size, toolsHeight, heightMargin = self.getFrameSize()
        grayDarkness = 0.9  # 1 is black
        self.w = window(width=size,
                        height=size + toolsHeight,
                        title="Origami Simulator")
        self.scene = display(window=self.w,
                             x=0,
                             y=0,
                             width=size,
                             height=size,
                             ambient=color.gray(grayDarkness),
                             background=BACKGROUND_COLOR)

        self.initToolbar()
        # from http://www.wxpython.org/doriginalCoords/api/
        # wx.Window-class.html#SetSizeHints
        self.w.win.SetSizeHints(minW=size,
                                minH=size + toolsHeight + heightMargin,
                                maxW=size,
                                maxH=size + toolsHeight + heightMargin)

        # == THE THUMBNAIL PANEL ==
        panelHeight = 100
        self.panel = wx.Panel(parent=self.w.win,
                              pos=(0, size),
                              size=(size, panelHeight))
        self.panel.Bind(wx.EVT_PAINT, lambda event: self.OnPaint(event))

        self.origami = Origami()
        self.mode = 1
        self.tb.EnableTool(self.editID, False)  # disable edit
        self.tb.EnableTool(self.prevID, False)  # disable prev
        self.tb.EnableTool(self.nextID, False)  # disable next

        self.scene.bind('mousedown', self.mouseDown)
        self.scene.bind('keydown', self.keyPressed)
        self.init()
        self.loop()
Ejemplo n.º 5
0
DSrad = 1.0  # radius of Death Snowball
DSpos = vector(7.0, 0.0, 0.0)  # position vector of Death Snowball
DeathSnowball = sphere(pos=DSpos,
                       radius=DSrad,
                       color=color.white,
                       make_trail=True)
vel_DS = vector(0.0, 0.0, 0.0)  # initial velocity of Death Snowball

### The Death Star ###
M2 = 2000  # mass of Death Star
DS2rad = 0.5  # radius of Death Star
DS2pos = vector(10.0, -2.0, 0.0)  # position vector of Death Star
vel_DS2 = vector(0, 15.0, 0.0)  # initial velocity of Death Star
DeathStar = sphere(pos=DS2pos,
                   radius=DS2rad,
                   color=color.gray(0.5),
                   make_trail=True)

## Olaf, the Sith Snowman ###
# You will need to complete this section yourself following the specification in the script
OlafAngle = np.radians(45)  # angle of Olaf's position relative to DS centre
OlafRad = 0.1  # Olaf's radius
Olafx = np.dot(DSpos, (1.0, 0.0, 0.0)) + (OlafRad + DSrad) * np.cos(
    OlafAngle
)  # Olaf's x-coordinate. Trigonometry used to position Olaf while accounting for radius of both.
Olafy = np.dot(DSpos, (0.0, 1.0, 0.0)) + (OlafRad + DSrad) * np.sin(
    OlafAngle
)  # Olaf's y-coordinate. Trigonometry used to position Olaf while accounting for radius of both.
Olaf = sphere(pos=(Olafx, Olafy, 0),
              radius=OlafRad,
              color=color.white,
Ejemplo n.º 6
0
from visual import window, color, vector, scene, frame, faces, curve, cross, rate, pi, rotate
from copy import *
import operator
import wx
import wx.lib.scrolledpanel as scrolled
import os
import sys
import numpy as np
import xml.etree.ElementTree as ET
from xml.dom import minidom
from functools import reduce

# SETTINGS
FRONT_COLOR = color.yellow
BACK_COLOR = color.white
BACKGROUND_COLOR = color.gray(0.2)  # 0 is white, 1 is black


def vertexOnEdge(edge, coords):
    # gives back the Vertex that exists at the coords on the edge by
    # calculating its original coordinates
    v1X, v1Y, v1Z = edge.ends[0].coords
    v2X, v2Y, v2Z = edge.ends[1].coords
    if v1X != v2X:
        ratio = (v1X - coords.x) / (v1X - v2X)
    elif v1Y != v2Y:
        ratio = (v1Y - coords.y) / (v1Y - v2Y)
    # calculate the origimalCoords
    originX = v1X - (v1X - v2X) * ratio
    originY = v1Y - (v1Y - v2Y) * ratio
    originZ = v1Z - (v1Z - v2Z) * ratio
Ejemplo n.º 7
0
def getelement(frame=None, which='E'):
    """This returns a single dipole arm, positioned at (0,0,0). It is returned in the 'frame'
     object provided. The value of 'which' (either 'N', 'S', 'E', or 'W') determines
     the orientation and position of the dipole returned.

     Call this function four times, for each of N,S,E, and W with the same frame
     object to build up a complete Christmas Tree.

     A tuple of (element, olist) is returned, where element is the frame containing the dipole arm,
     and olist is a list containing all the component objects in the element.
  """
    element = visual.frame(frame=frame,
                           axis=V(1, 0,
                                  0))  # Create a sub-frame for this dipole arm
    # The pipe object is the 'vertical' from base to top centre
    pipe = visual.curve(frame=element,
                        pos=[V(0, 0, 0), R],
                        radius=PIPER,
                        material=PIPEMAT,
                        color=color.gray(0.7))

    # These define the nine dipole loops, odd numbers on one side and even on the other.
    d1 = visual.curve(frame=element,
                      pos=[A, S, T, B],
                      radius=WIRER,
                      material=WIREMAT,
                      color=color.gray(0.7))
    d3 = visual.curve(frame=element,
                      pos=[E, W, Z, F],
                      radius=WIRER,
                      material=WIREMAT,
                      color=color.gray(0.7))
    d5 = visual.curve(frame=element,
                      pos=[I, C1, D1, J],
                      radius=WIRER,
                      material=WIREMAT,
                      color=color.gray(0.7))
    d7 = visual.curve(frame=element,
                      pos=[M, G1, H1, N],
                      radius=WIRER,
                      material=WIREMAT,
                      color=color.gray(0.7))
    d9 = visual.curve(frame=element,
                      pos=[Q, K1, L1, R],
                      radius=WIRER,
                      material=WIREMAT,
                      color=color.gray(0.7))

    d2 = visual.curve(frame=element,
                      pos=[C, U, Vp, D],
                      radius=WIRER,
                      material=WIREMAT,
                      color=color.gray(0.7))
    d4 = visual.curve(frame=element,
                      pos=[G, A1, B1, H],
                      radius=WIRER,
                      material=WIREMAT,
                      color=color.gray(0.7))
    d6 = visual.curve(frame=element,
                      pos=[K, E1, F1, L],
                      radius=WIRER,
                      material=WIREMAT,
                      color=color.gray(0.7))
    d8 = visual.curve(frame=element,
                      pos=[O, I1, J1, P],
                      radius=WIRER,
                      material=WIREMAT,
                      color=color.gray(0.7))

    # Rotate the dipole arm so it's vertical (parallel to Z axis), instead of in the XY plane.
    element.rotate(angle=visual.pi / 2, axis=V(1, 0, 0), pos=V(0, 0, 0))

    if which == 'E':
        element.pos = V(0, -0.354,
                        0)  # Shift it so it's above the East mounting point
        element.rotate(angle=-0.20184, axis=V(
            1, 0, 0), pos=element.pos)  # Rotate it so the top is above (0,0,0)
    elif which == 'W':
        element.rotate(
            angle=visual.pi, axis=V(0, 0, 1)
        )  # Rotate it vertically so the dipoles face in the right direction
        element.pos = V(0, 0.354,
                        0)  # Shift it so it's above the West mounting point
        element.rotate(angle=0.20184, axis=V(
            1, 0, 0), pos=element.pos)  # Rotate it so the top is above (0,0,0)
    elif which == 'S':
        element.rotate(
            angle=-visual.pi / 2, axis=V(0, 0, 1)
        )  # Rotate it vertically so the dipoles face in the right direction
        element.pos = V(-0.354, 0,
                        0)  # Shift it so it's above the South mounting point
        element.rotate(angle=0.20184, axis=V(
            0, 1, 0), pos=element.pos)  # Rotate it so the top is above (0,0,0)
    elif which == 'N':
        element.rotate(
            angle=visual.pi / 2, axis=V(0, 0, 1)
        )  # Rotate it vertically so the dipoles face in the right direction
        element.pos = V(0.354, 0,
                        0)  # Shift it so it's above the North mounting point
        element.rotate(angle=-0.20184, axis=V(
            0, 1, 0), pos=element.pos)  # Rotate it so the top is above (0,0,0)
    return element, [pipe, d1, d2, d3, d4, d5, d6, d7, d8, d9]
Ejemplo n.º 8
0
                             radius=20.0,
                             axis=V(0, 0, 0.2),
                             material=GMAT)

    posfile = open('aavspositions.txt', 'r')
    lines = posfile.readlines()
    bases = []
    for line in lines:  # Loop over all AAVS1.0 dipole positions
        x, y = tuple(map(float, line.split(
        )))  # Get the N/S and E/W coordinates, in meters from the centre

        # Create the base object at that position, by extruding the 2D shape (basep) up in the Z direction by 0.065m.
        b = visual.extrusion(pos=[V(x, y, 0.0), V(x, y, 0.065)],
                             shape=basep,
                             material=materials.rough,
                             color=color.gray(0.4))
        bases.append(b)

        # Create a Christmas Tree object at that position
        tree, elist = getxmas()
        tree.pos = (x, y, 0.065)
        cable = gettreecable(
            tree.pos
        )  # And add a cable tail from the Christmas Tree, pointing towards the centre

    eaxis = visual.arrow(pos=V(0, 0, 0),
                         axis=V(2, 0, 0),
                         color=color.blue,
                         shaftwidth=0.1,
                         fixedwidth=True,
                         opacity=0.2)
Ejemplo n.º 9
0
    rotation_matrices = [array([[q[3] ** 2 + q[0] ** 2 - q[1] ** 2 - q[2] ** 2, 2.0 * (q[0] * q[1] - q[3] * q[2]), 2.0 * (q[0] * q[2] + q[3] * q[1])],
                                [2.0 * (q[0] * q[1] + q[3] * q[2]), q[3] ** 2 - q[0] ** 2 + q[1] ** 2 - q[2] ** 2, 2.0 * (q[1] * q[2] - q[3] * q[0])],
                                [2.0 * (q[0] * q[2] - q[3] * q[1]), 2.0 * (q[1] * q[2] + q[3] * q[0]), q[3] ** 2 - q[0] ** 2 - q[1] ** 2 + q[2] ** 2]]) for q in quaternions]

scene.background=(1,1,1)
scene.up = vector(0, 0, 1)

asteroid_3d = ellipsoid(pos=(0.0, 0.0, 0.0), up=(0.0, 0.0, 1.0),
                        length=2.0 * sim_params[0],
                        width=2.0 * sim_params[1],
                        height=2.0 * sim_params[2],
                        color=(153.0 / 255.0, 76.0 / 255.0, 0.0))

spacecraft = box(pos=tuple(states[0][0:3]), size=(100, 100, 100), make_trail=True,
                 color=(0.0, 128.0 / 255.0, 1.0), up=(0.0, 0.0, 1.0))
spacecraft.trail_object.color = color.gray(0.0)

height = arrow(pos=spacecraft.pos-states[0][3:7], axis=tuple(states[0][3:7]), shaftwidth=20.0,
               color=color.orange, up=(0.0, 0.0, 1.0))

if reference_frame == "body":
    ground_position = sphere(pos=height.pos, radius=5.0, make_trail=True, color=(0.0, 0.0, 204.0 / 255.0))
    ground_position.trail_object.color = (255.0 / 255.0, 255.0 / 255.0, 255.0 / 255.0)

else:
    ground_position = sphere(pos=height.pos, radius=5.0, color=(0.0, 0.0, 204.0 / 255.0))

norms = [asteroid_3d.length * 0.75, asteroid_3d.width * 0.75, asteroid_3d.height * 0.75]

if reference_frame == "body":
    x_axis = arrow(pos=(0, 0, 0), axis=(norms[0], 0.0, 0.0), shaftwidth=100.0, color=color.green)
# All values are in Galactic Natural Units except where stated otherwise

## The Death Snowball ###
M = 2000 # mass of Death Snowball 
DSrad = 1.0 # radius of Death Snowball
DSpos = vector(7.0,0.0,0.0) # position vector of Death Snowball
DeathSnowball = sphere(pos=DSpos,radius=DSrad,color=color.white,make_trail=True)
vel_DS = vector(0.0,0.0,0.0) # initial velocity of Death Snowball


### The Death Star ###
M2 = 2000 # mass of Death Star
DS2rad = 0.5 # radius of Death Star
DS2pos = vector(10.0,-2.0,0.0) # position vector of Death Star
vel_DS2 = vector(0,15.0,0.0) # initial velocity of Death Star 
DeathStar = sphere(pos=DS2pos,radius=DS2rad,color=color.gray(0.5),make_trail=True)

## Olaf, the Sith Snowman ###
# You will need to complete this section yourself following the specification in the script
OlafAngle = np.radians(45) # angle of Olaf's position relative to DS centre
OlafRad = 0.1 # Olaf's radius
Olafx= # Olaf's x-coordinate COMPLETE THIS LINE
Olafy= # Olaf's y-coordinate COMPLETE THIS LINE
Olaf = sphere(pos=(Olafx,Olafy,0),radius= OlafRad,color=color.white,opacity=0.5) 

### Angry Jedi bird ###
mbird = 1 # mass of angry bird, may be *much* bigger than 1 later
initpos = vector(0,0,0) # initial position vector of bird
Bird= sphere(pos=initpos,radius=0.1,color=color.red,make_trail=True)
Bird.trail_object.color=color.white # make the trail white