def animate(solar_sys, satellite, t, dt, curves, point): orbit = satellite.orbit new_pos = orbit_xyz(t, orbit['theta'], orbit['phi']) * \ (solar_sys['earth_radius'] + orbit['altitude']) satellite.sat3d.pos = vecflip(new_pos, solar_sys['flip_o']) new_psi = get_psi(t, orbit['psi_mode']) new_up = rotate_vector((0, 0, 1), orbit['theta'], orbit['phi'], new_psi) satellite.sat3d.up = vecflip(new_up, solar_sys['flip_o']) satellite.zrot = (satellite.zrot + get_zrot(dt / orbit['zrot_period'])) % (2 * n.pi) satellite.sat3d.rotate(angle=get_zrot(dt / orbit['zrot_period']), axis=satellite.sat3d.up) satellite.sat_v3d.up = vecflip(new_up, flip=solar_sys['flip_v'], signs=(-1, 1, 1)) # https://ocw.mit.edu/courses/aeronautics-and-astronautics/16-851-satellite-engineering-fall-2003/projects/portfolio_nadir1.pdf eclipse_frac = 0.5 total_power_gen = 0 for i in range(satellite.starting_orientation.shape[0]): satellite.current_orientation[i] = rotate_vector( satellite.starting_orientation[i], orbit['theta'], orbit['phi'], new_psi) satellite.area_ratio[i], satellite.normal_angles[i] = dot_and_angle( solar_sys['sun_vector'], satellite.current_orientation[i]) power_gen = -1.0 * solar_sys['solar_flux'] * ( 1 / 10000.0) * satellite.cell_areas[i] * 0.3 * satellite.area_ratio[i] if power_gen < 0 or t < eclipse_frac: power_gen = 0 total_power_gen += power_gen curves[i].plot([point * dt, power_gen]) satellite.gen_powers_per_face[i, point] = power_gen curves[6].plot(point * dt, total_power_gen) # print(new_up) # print (satellite.area_ratio) # print (satellite.normal_angles) # print (satellite.current_orientation) # equation here to determine true eclipse frac if t < eclipse_frac: solar_sys['sun_v'].color = color.gray(0) else: solar_sys['sun_v'].color = color.gray(0.6)
def gettile(cpos=None): if cpos is None: cpos = v((0, 0, 0)) elif type(cpos) == tuple: cpos = v(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 = vpython.box(pos=v(0, 0, 0) + cpos, axis=v(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=v(xoffsets[i], yoffsets[i], 0) + cpos) olist += dlist return olist
def make_orbit_scene(solar_sys, satellite): rsun = solar_sys['sun_radius'] rearth = solar_sys['earth_radius'] psun = solar_sys['sun_dist'] * n.array(solar_sys['sun_vector']) pearth = (0, 0, 0) altitude = satellite.orbit['altitude'] psat = (0, 0, rearth + altitude) size_sat = satellite.properties['sizefactor'] up_sat = satellite.starting_orientation[4] scene = canvas() sun = sphere(pos=vecflip(psun, solar_sys['flip_o']), radius=rsun, emissive=True, color=color.yellow) earth = sphere(pos=vecflip(pearth, solar_sys['flip_o']), radius=rearth, color=color.green, make_trail=False) scene.lights = [] sunlight = local_light(pos=vecflip(psun, solar_sys['flip_o']), color=color.gray(0.4)) scene.ambient = color.gray(0.5) sat = box(pos=vecflip(psat, solar_sys['flip_o']), length=0.1 * size_sat, width=0.1 * size_sat, height=0.3 * size_sat, up=vecflip(up_sat, solar_sys['flip_o']), make_trail=True) solar_sys['sun'] = sun solar_sys['earth'] = earth satellite.sat3d = sat satellite.zrot = 0 return scene, solar_sys, satellite
def make_view_scene(solar_sys, satellite): psun = (0, solar_sys['sun_dist'], 0) up_sat = satellite.starting_orientation[4] sat_view_scene = canvas() sat_view = box(pos=vecflip((0, 0, 0), flip=solar_sys['flip_v']), width=0.1, length=0.1, height=0.3, up=vecflip(up_sat), make_trail=True) sat_view_scene.lights = [] sat_view_scene.ambient = color.gray(0.3) sun_view = local_light(pos=vecflip(psun, flip=solar_sys['flip_v']), color=color.gray(0.4)) # sat_view.axis = vecflip(sat_axis) solar_sys['sun_v'] = sun_view satellite.sat_v3d = sat_view return sat_view_scene, solar_sys, satellite
def __init__(self): self.db = Database('flatstack.db') self.db.create_default_tables() self.scene = canvas() self.scene.background = color.gray(0.8) self.scene.forward = vec(0,-0.2,-1) self.scene.fov = 0.2 self.set_range() self.scene.caption = """Right button drag or Ctrl-drag to rotate "camera" to view scene. To zoom, drag with middle button or Alt/Option depressed, or use scroll wheel. On a two-button mouse, middle is left + right. Touch screen: pinch/extend to zoom, swipe or two-finger rotate.\n""" self.clear()
def gettile(offsets=None, cpos=None): """Create and return a list of 3D objects making up a single MWA tile. If cpos is given, it's used as the center position for the whole tile (if you want to show multiple tiles). """ if offsets is None: offsets = TILEOFFSETS if cpos is None: cpos = v(0, 0, 0) elif type(cpos) == tuple: cpos = v(cpos) eaxis = vpython.arrow(pos=v(0, 0, 0), axis=v(3, 0, 0), color=color.blue, shaftwidth=0.1, fixedwidth=True, opacity=0.2) naxis = vpython.arrow(pos=v(0, 0, 0), axis=v(0, 3, 0), color=color.blue, shaftwidth=0.1, fixedwidth=True, opacity=0.2) eaxislabel = vpython.text(text='E', pos=v(3, 0, 0.2), height=0.5, depth=0.1, color=color.blue, opacity=0.2) naxislabel = vpython.text(text='N', pos=v(0, 3, 0.2), height=0.5, depth=0.1, color=color.blue, opacity=0.2) gp = vpython.box(pos=v(0, 0, 0) + cpos, axis=v(0, 0, 1), height=5.0, width=5.0, length=0.05, color=color.gray(0.5)) olist = [eaxis, naxis, eaxislabel, naxislabel, gp] letters = 'ABCDEFGHIJKLMNOP' for i in range(16): xy = offsets[i] p = v(xy[0], xy[1], 0) + cpos dlist = getdipole(cpos=p, dlabel=letters[i]) olist += dlist return olist
def geteda(offsets=EDAOFFSETS): """Create and return a list of 3D objects making up the entire 256 element Engineering Development Array, using the dipole locations in locations.txt """ gp = vpython.box(pos=v(0, 0, 0), axis=v(0, 0, 1), height=40.0, width=40.0, length=0.05, color=color.gray(0.5)) olist = [gp] for bfid in pointing.HEXD: for dipid in pointing.HEXD: dlist = getdipole(cpos=v(*offsets[bfid][dipid]), dlabel=bfid + dipid) olist += dlist eaxis = vpython.arrow(pos=v(0, 0, 0), axis=v(20, 0, 0), color=color.blue, shaftwidth=0.1, fixedwidth=True, opacity=0.2) naxis = vpython.arrow(pos=v(0, 0, 0), axis=v(0, 20, 0), color=color.blue, shaftwidth=0.1, fixedwidth=True, opacity=0.2) eaxislabel = vpython.text(text='E', pos=v(20, 0, 0.2), height=0.5, depth=0.1, color=color.blue, opacity=0.2) naxislabel = vpython.text(text='N', pos=v(0, 20, 0.2), height=0.5, depth=0.1, color=color.blue, opacity=0.2) olist += [eaxis, naxis, eaxislabel, naxislabel] return olist
def create_cylinder(self, x, y, MIC, mut_list, prom): disks = [] a = [] disks = [ self.disk_height for i in range(int(MIC // self.disk_height)) ] + [ MIC % self.disk_height for i in range(1) if MIC % self.disk_height != 0 ] # while MIC != 0: # if MIC > self.disk_height: # disks.append(self.disk_height) # MIC -= self.disk_height # else: # disks.append(MIC) # MIC -= MIC j = .15 for i in range(len(disks)): a.append( cylinder(pos=vector(x, y, sum(disks[:i])), axis=vector(0, 0, disks[i]), radius=self.cylinder_diameter, color=color.gray(j))) # ,material=materials.unshaded j += .1 kk = vector(255.0 / 255.0, 248.0 / 255.0, 220.0 / 255.0) a.append( cylinder(pos=vector(x, y, MIC + .1), axis=vector(0, 0, .1), radius=self.cylinder_diameter * .95, color=kk)) posn = vector(x, y, MIC) b = self.variants_on_top(posn, mut_list) if prom == 1: c = self.middle_variant_on_top(posn) return a + b + c else: return a + b
polline.color = color.green attach_trail(polline, radius=0.006, retain=70, pps=4, type='points') for index in range(N): particella = sphere() particella.mass = 0.01 particella.radius = 0.015 particella.pos = vector.random() particella.velocity = vector.random() particella.color = color.orange particelle.append(particella) # Disegna un cubo di lato 2d d = 1 # semilato del cubo r = 0.005 gray = color.gray(0.7) boxbottom = curve(color=gray, radius=r) boxbottom.append([ vector(-d, -d, -d), vector(-d, -d, d), vector(d, -d, d), vector(d, -d, -d), vector(-d, -d, -d) ]) boxtop = curve(color=gray, radius=r) boxtop.append([ vector(-d, d, -d), vector(-d, d, d), vector(d, d, d), vector(d, d, -d), vector(-d, d, -d)
#finding every line between two points of different class couples = list(itertools.product(ind_abo, ind_bel)) intersection_point = [] for couple in couples: v1 = vor.vertices[sel_reg][couple[0]] v2 = vor.vertices[sel_reg][couple[1]] intersection_point.append(plane_z_intersection(v1, v2, sel_z)) intersection_point = np.asarray(intersection_point) intersection_point intersectiong_triang = Delaunay(intersection_point[:, 0:2]) #%%----------------------------------------------------------------------------- scene = canvas(width=900, height=700, center=vector(5, 5, 0), background=color.gray(1)) # scene.camera.pos = vector(0,5,sel_z) # scene.camera.axis = vector(5,0,0) turquoise = color.hsv_to_rgb(vector(0.5, 1, 0.8)) red = color.red #Some colors white = color.white green = color.green yellow = color.yellow Figures = [] #List to which append all the drawings draw_axis(Figures, max_coord) #drawing points ABOVE for ver in vor.vertices[sel_reg][ind_abo]:
site_radius = 0.1 link_radius = 0.05 # Site and link colors in RGB (decimal) values link_color = vector(.26, .75, .96) site_color = vector(.14, .03, .96) # Canvas and background color scene = canvas(title='Lattice', width=1000, height=700, center=vector(0,0,0), background=color.white) # Lighting scene.lights = [] distant_light(direction=vector(2,2,2), color=color.gray(0.9)) # Generate the lattice for i in range(lattice_size + 1): for j in range(lattice_size + 1): for k in range(lattice_size + 1): sphere(pos=vector(i,j,k),radius=site_radius, color=site_color) cylinder(pos=vector(i,j,k), axis=vector(1,0,0), radius=link_radius, color=link_color) cylinder(pos=vector(i,j,k), axis=vector(0,1,0), radius=link_radius, color=link_color) cylinder(pos=vector(i,j,k), axis=vector(0,0,1), radius=link_radius, color=link_color) # Create origin/axes arrow(pos=vector(-1,-1,-1), axis=vector(0,0,1), radius=.1, color=color.green) arrow(pos=vector(-1,-1,-1), axis=vector(0,1,0), radius=.1, color=color.green) arrow(pos=vector(-1,-1,-1), axis=vector(1,0,0), radius=.1, color=color.green) label(pos=vector(0,-1,-1), text='x')
size=vector(1, 40, 40), color=color.red) topBorder = box(pos=vector(0, 20, 0), size=vector(40, 1, 40), color=color.blue) bottomBorder = box(pos=vector(0, -20, 0), size=vector(40, 1, 40), color=color.blue) frontBorder = box(pos=vector(0, 0, 20), size=vector(40, 40, 1), color=color.red, opacity=0.1) bgBorder = box(pos=vector(0, 0, -20), size=vector(40, 40, 1), color=color.gray(0.8)) ball.trail = curve(color=ball.color) vx = 12 vy = 10 vz = 8 ball.velocity = vector(vx, vy, vz) dt = 0.01 t = 0 while t < 20: rate(100) ball.pos = ball.pos + (ball.velocity * dt)
# modify init axis upper_arm_main_axis = (joint_anchor.pos-shoulder_anchor.pos).norm() upper_arm_sub_axis = upper_arm_main_axis.cross(front).cross( upper_arm_main_axis).norm() small_arm_main_axis = (hand_anchor.pos-joint_anchor.pos).norm() small_arm_sub_axis = small_arm_main_axis.cross(front).cross( small_arm_main_axis).norm() [e.rotate(origin=joint_anchor.pos, axis=small_arm_main_axis, angle=radians(-80)) for e in [small_arm]] [e.rotate(origin=joint_anchor.pos, axis=small_arm_sub_axis, angle=radians(20)) for e in [small_arm, hand_anchor]+joint_axis] small_arm_main_axis = (hand_anchor.pos-joint_anchor.pos).norm() small_arm_sub_axis = small_arm_main_axis.cross(front).cross( small_arm_main_axis).norm() distant_light(direction=up*10-front*2, color=color.gray(0.8)) print('Click scene to continue') scene.waitfor('click keydown') def motion_backing(): m1 = motion_backing_upper_arm() if m1: return True m2 = motion_backing_small_arm() return any([m1, m2]) def motion_backing_upper_arm(angle=radians(2)): # return False, if we are fine
def turtle_interpretation_3D(scene, instructions, delta=22.5, width=0.3, widthScaling=0.7, tropismVec=vector(0, 0, 0), tropismStrength=0): """Interprets a set of instructions for a turtle to draw a tree in 3D. """ ############ INITIALIZATION ############# bob = Turtle3D(width=width) turtlePosStack = [] turtleHeadStack = [] turtleXmax = 0 turtleXmin = 0 turtleYmax = 0 turtleYmin = 0 turtleZmax = 0 turtleZmin = 0 ######### MAIN FUNCTION ############## for mod in instructions: if mod.symbol == "F": bob.applyTropism(tropismVec, tropismStrength) if mod.param == []: bob.forward() else: bob.forward(mod.param[0]) #Note that we only need to update the max coordinates if the turtle has moved turtleXmax = max(turtleXmax, bob.xcor()) turtleXmin = min(turtleXmin, bob.xcor()) turtleYmax = max(turtleYmax, bob.ycor()) turtleYmin = min(turtleYmin, bob.ycor()) turtleZmax = max(turtleZmax, bob.zcor()) turtleZmin = min(turtleZmin, bob.zcor()) elif mod.symbol == "f": bob.penUp() if mod.param == []: bob.forward() else: bob.forward(mod.param[0]) bob.penDown() elif mod.symbol == "+": if mod.param == []: bob.turnLeft(delta) else: bob.turnLeft(mod.param[0]) elif mod.symbol == "-": if mod.param == []: bob.turnRight(delta) else: bob.turnRight(mod.param[0]) elif mod.symbol == "&": if mod.param == []: bob.pitchDown(delta) else: bob.pitchDown(mod.param[0]) elif mod.symbol == "^": if mod.param == []: bob.pitchUp(delta) else: bob.pitchUp(mod.param[0]) elif mod.symbol == "\\": if mod.param == []: bob.rollLeft(delta) else: bob.rollLeft(mod.param[0]) elif mod.symbol == "/": if mod.param == []: bob.rollRight(delta) else: bob.rollRight(mod.param[0]) elif mod.symbol == "|": bob.turnLeft(180) elif mod.symbol == "[": turtlePosStack.insert(0, bob.getPosition()) turtleHeadStack.insert(0, bob.getHeading()) bob.pushCurve() elif mod.symbol == "]": bob.setPosition(turtlePosStack.pop(0)) bob.setHeading(turtleHeadStack.pop(0)) bob.popCurve() elif mod.symbol == "!": if mod.param == []: bob.decrementDiameter(widthScaling) else: bob.setWidth(mod.param[0]) elif mod.symbol == "{": bob.startPolygon() elif mod.symbol == "}": bob.endPolygon() elif mod.symbol == "'": bob.setColor(mod.param) #point the camera to the center of our drawing xcenter = 0 ycenter = (turtleYmax + turtleYmin) / 2 zcenter = 0 scene.center = vector(xcenter, ycenter, zcenter) # draw a ground plane bob.drawGround(max(turtleXmax, turtleZmax) * 2) # set lighting scene.lights = [] # reset default lighting scene.ambient = color.gray(0.3) distant_light(direction=vector(0.22, 0.44, 0.88), color=color.gray(0.7)) distant_light(direction=vector(-0.88, -0.22, -0.44), color=color.gray(0.3)) distant_light(direction=vector(-0.22, -0.44, -0.88), color=color.gray(0.7)) distant_light(direction=vector(0.88, 0.22, 0.44), color=color.gray(0.3)) return 0
from math import atan2, sin, cos, log, sqrt, pi from numpy import zeros, max from numpy.fft import fft import scipy.constants import matplotlib.pyplot as plt from vpython import vec, mag, sphere, rate, color, arrow, quad, vertex, canvas, cross scene = canvas( title= "right mouse=rotate, wheel=zoom, left=resize scene; Fourier analysis follows after time integration has terminated", width=1280, height=800, background=color.gray(0.5)) # Orbitrap settings R_1 = 12.0e-3 / 2 R_2 = 30.0e-3 / 2 R_m = 1.1 * R_2 * sqrt(2.0) U_r = 3.5e3 k = 2 * U_r / (R_m**2 * log(R_2 / R_1) - (R_2**2 - R_1**2) / 2) N_t = 2**13 kappa = 100 # particle settings u = scipy.constants.physical_constants["atomic mass constant"][0] q = 1 * scipy.constants.e m = 12 * u R = (3 * R_1 + R_2) / 4 v_phi = sqrt((k / 2) * (q / m) * (R_m**2 - R**2))