def setUp(self): # Set up a scene to visualize self.meterstick = phy.MovingObject(0, length=3/5, velocity=4/5) self.tlim = (0, 2) self.xlim = (0, 2.2) self.vertices_moving = [[0, 0], [3/5, 0], [2.2, 2], [1.6, 2], [0, 0]] self.vertices_rest = [[0, 0], [1, 0], [1, 2], [0, 2], [0, 0]] # Over 3 frames of time self.fps = 1 self.ct_per_sec = 1 self.xdata_moving = [[0, 3/5], [4/5, 7/5], [8/5, 11/5]] self.xdata_rest = 3*[[0, 1]]
#!/usr/bin/env python3 import sys sys.path.append('..') import specrel.geom as geom import specrel.graphics.companim as canim import specrel.spacetime.physical as phy import specrel.visualize as vis # Planets origin = 0 planetdist = 1 x_planet = origin + planetdist earth = phy.MovingObject(origin, draw_options={'color': 'blue', 'markersize': 20, 'label': 'Earth'}) planet = phy.MovingObject(x_planet, draw_options={'color': 'purple', 'markersize': 15, 'label': 'Planet'}) # Rocket v = 3/5 rocket_forward_alltime = phy.MovingObject(origin, velocity=v) t_turnaround = rocket_forward_alltime.time_for_left_pos(x_planet) rocket_forward = geom.line_segment((0, 0), (t_turnaround, x_planet), draw_options={ 'color': 'cyan', 'marker': '>', 'markersize': 5, 'linestyle': ':', 'label': 'Traveler (forward)', } )
#!/usr/bin/env python3 import sys sys.path.append('..') import specrel.geom as geom import specrel.spacetime.physical as phy import specrel.visualize as vis # A Lorentz-boosted satellite system v = 4 / 5 earth = phy.MovingObject(0, draw_options={'label': 'Earth', 'color': 'blue'}) rocket = phy.MovingObject(0, velocity=v, draw_options={ 'label': 'Rocket', 'color': 'gray' }) satellite = phy.MovingObject(0, velocity=v, draw_options={ 'label': 'Satellite', 'color': 'red' }) light = phy.MovingObject(0, velocity=1, draw_options={ 'label': 'Light', 'color': 'gold' }) satellite.lorentz_boost(v) objects = geom.Collection([earth, rocket, satellite, light])
#!/usr/bin/env python3 import sys sys.path.append('..') import specrel.graphics.companim as canim import specrel.geom as geom import specrel.spacetime.physical as phy import specrel.visualize as vis # Ladder information v = 4/5 ladder_left_start = 0 ladder_length = 1 alpha = 0.5 # For transparency ladder = phy.MovingObject(ladder_left_start, ladder_length, v, draw_options={'color': (0, 0, 1, alpha), 'label': 'Ladder'}) # Garage information garage_left_start = 4 garage = phy.MovingObject(garage_left_start, ladder_length, draw_options={ 'facecolor': (1, 0.5, 0, alpha), 'edgecolor': 'limegreen', 'label': 'Garage', } ) # Add a few more frills to the drawing door_draw_options = {'linestyle': '--', 'marker': '|', 'markersize': 10} garage[0].draw_options = door_draw_options garage[1].draw_options = door_draw_options
import sys sys.path.append('..') import specrel.geom as geom import specrel.spacetime.physical as phy import specrel.visualize as vis # Shared parameters include_grid = True include_legend = True tlim = (0, 2) xlim = (-2, 2) # A stationary point object stationary = phy.MovingObject(0, draw_options={'label': '$v = 0$'}) ## Alternate: # direction = (1, 0) # point = (0, 0) # stationary = geom.Line(direction, point, draw_options={'label': '$v = 0$'}) title = 'Stationary object' p = vis.stplot(stationary, title=title, tlim=tlim, xlim=xlim, grid=include_grid, legend=include_legend) p.save('2-objects_stationary_point.png') p.show() # A stationary point object, animated
#!/usr/bin/env python3 import sys sys.path.append('..') import specrel.geom as geom import specrel.spacetime.physical as phy import specrel.visualize as vis # An FTL meterstick v_ftl = 2 v_frame = 4/5 meterstick = phy.MovingObject(-0.5, 1, velocity=v_ftl) tlim = (-1, 1) xlim = (-2, 2) include_grid = True anim = vis.animate_lt(meterstick, v_frame, tlim=tlim, xlim=xlim, title='FTL meterstick in different frames', grid=include_grid) anim.save('7-ftl_meterstick.mp4') anim.show() # FTL communication # Set up this system in the "median" frame tlim = (0.5, 1.9) xlim = (-1.6, 1.6) v_away = 1/2 v_message = 4 t_send = 1 person1 = phy.MovingObject(0, velocity=-v_away, draw_options={'color': 'red', 'label': 'Person 1', 'markersize': 15}) person2 = phy.MovingObject(0, velocity=v_away, draw_options={'color': 'blue', 'label': 'Person 2', 'markersize': 15})
def test_has_extent(self): self.assertTrue(self.obj.has_extent()) self.assertFalse(phy.MovingObject(1, 0, 0.5).has_extent())
def setUp(self): self.obj = phy.MovingObject(1, length=1, velocity=0.5)
#!/usr/bin/env python3 import sys sys.path.append('..') import specrel.geom as geom import specrel.spacetime.physical as phy import specrel.visualize as vis tlim = (-5, 5) xlim = (-5, 5) # Draw more lines than needed right now; they will appear once we transform stgrid = phy.stgrid([2 * t for t in tlim], [2 * x for x in xlim]) light_draw_options = {'color': 'gold'} left_light = phy.MovingObject(0, velocity=-1, draw_options=light_draw_options) right_light = phy.MovingObject(0, velocity=1, draw_options=light_draw_options) grid_with_light = geom.Collection([stgrid, left_light, right_light]) v = 3 / 5 anim = vis.animate_lt(grid_with_light, v, tlim=tlim, xlim=xlim, lim_padding=0, title='The Lorentz transformation') anim.save('3-lorentztransform.mp4') anim.show() # Transform about a different origin origin = geom.STVector(2, 1, tag='origin',
tlim = (0, duration + 0.5) xlim = (-0.5, 0.5) anim = vis.compare_frames_animated_with_worldline( onesecond, v, tlim=tlim, xlim=xlim, instant_pause_time=0, linewidth=10, title='Time interval in different frames', current_time_color='cyan') anim.save('5-timedilation2.mp4') anim.show() # Length contraction of a meterstick meterstick = phy.MovingObject(-0.5, 1) tlim = (0, 2) xlim = (-2, 0.5) meterstick = grad.longitudinal_gradient_ribbon( [(tlim[0], meterstick.left_pos(tlim[0])), (tlim[1], meterstick.left_pos(tlim[1]))], [(tlim[0], meterstick.right_pos(tlim[0])), (tlim[1], meterstick.right_pos(tlim[1]))], 'red', 'blue') anim = vis.compare_frames_animated_with_worldline( meterstick, v, tlim=tlim, xlim=xlim, title='Meterstick in different frames', instant_pause_time=0, linewidth=10,