TransWikia.com

How to draw tilted axes for spacetime diagrams

Mathematica Asked by Fritz Dewit on January 4, 2021

I want to use Mathematica to draw spacetime diagrams.


In particular, on one of these diagram, I’d like to draw two pairs of axes. The first pair $(t,,x)$ for the rest frame and the second pair $(t’,, x’)$ for the moving frame. Further, the axes for the moving frame should be tilted towards the $t = x$ line.

  1. Is there a way to do this?
  2. Is there a Mathematica package out there that does?

2 Answers

Here is a first try. I do not claim that it is perfect, but it may serve as a starting point.:

skeweaxes[{{xmin_, xmax_}, {ymin_, ymax_}}, phi_] := 
 Module[{nxti = 20, nyti = 20, xtlen = (ymax - ymin)/100, 
   ytlen = (xmax - xmin)/100},
  rot0 = RotationTransform[phi]; rot1 = RotationTransform[-phi];
  t0 = {rot0 /@ {{xmin, ymin}, {xmax, ymin}}, 
    rot1 /@ {{xmin, ymin}, {xmin, ymax}}};
  c = 0; t1 = 
   Table[rot0 /@ {{x, ymin}, {x, 
       ymin + xtlen If[Mod[++c, 5] == 1, 2, 1]}}, {x, xmin, 
     xmax, (xmax - xmin)/nxti}];
  c = 0; t2 = 
   Table[rot1 /@ {{xmin, y}, {xmin + ytlen If[Mod[++c, 5] == 1, 2, 1],
        y}}, {y, ymin, ymax, (ymax - ymin)/nyti}];
  
  Graphics[Line[Join[t0, t1, t2]]]
  ]
pl = Plot[{x, x^2}, {x, 0, 1}];
Show[{skeweaxes[{{0, 1}, {0, 1}}, Pi/8], pl}, AspectRatio -> 1, 
 Axes -> True]

enter image description here

Answered by Daniel Huber on January 4, 2021

Here's an approach based on the fifth argument of Inset:

Graphics[
 {
  Inset[
   Graphics[{},
    Frame -> {{True, False}, {True, False}},
    FrameTicksStyle -> (FontOpacity -> 0),
    PlotRange -> {{0, 1}, {0, 1}}
    ],
   {0, 0}, {0, 0}, {1, 1}, {{1, 0.5}, {0.5, 1}}
   ]
  },
 Frame -> {{True, False}, {True, False}},
 PlotRange -> {{0, 1}, {0, 1}}
 ]

enter image description here

The argument {{1, 0.5}, {0.5, 1}} specifies the direction of the x and y axis of the inner plot respectively. You'll need to compute the exact size the inset needs to be, but other than that there shouldn't be an issue. The other thing to note is that the ticks are also skewed for the tilted coordinate system, but since they point along the direction of the other axis, this might actually be a good thing. Assuming the size and axes directions are correct, it is also trivial to add additional content to the inner graphics and have it displayed in the same warped way as the axes themselves.

Answered by Lukas Lang on January 4, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP