Copyright | Copyright (C) 2023 Yoo Chung |
---|---|

License | All rights reserved |

Maintainer | web@chungyc.org |

Safe Haskell | Safe-Inferred |

Language | GHC2021 |

Defines coordinates for flat spacetime and provides functions to manipulate and transform them. It is intended to be a simple module sufficient enough to assist in drawing spacetime diagrams.

## Synopsis

- newtype Coordinate = Coordinate (Double, Double, Double, Double)
- plus :: Coordinate -> Coordinate -> Coordinate
- minus :: Coordinate -> Coordinate -> Coordinate
- scale :: (Double -> Double) -> Coordinate -> Coordinate
- combine :: (Double -> Double -> Double) -> Coordinate -> Coordinate -> Coordinate
- approximates :: Coordinate -> Coordinate -> Bool
- interval :: Coordinate -> Double
- transform :: Double -> Coordinate -> Coordinate
- transformation :: Double -> Transformation V2 Double
- vectorize2D :: Coordinate -> V2 Double
- axes :: Diagram B
- axesWith :: AxesOptions -> Diagram B
- axesOptions :: AxesOptions
- axesLength :: AxesOptions -> Double
- axesLightcone :: AxesOptions -> Bool
- data AxesOptions

# Coordinates

newtype Coordinate Source #

The coordinates \((t, x, y, z)\) in flat spacetime.

The coordinates use Planck units. In other words, \(c = 1\).

Coordinate (Double, Double, Double, Double) |

#### Instances

Generic Coordinate Source # | |

Defined in Physics.Spacetime.Flat type Rep Coordinate :: Type -> Type # from :: Coordinate -> Rep Coordinate x # to :: Rep Coordinate x -> Coordinate # | |

Show Coordinate Source # | |

Defined in Physics.Spacetime.Flat showsPrec :: Int -> Coordinate -> ShowS # show :: Coordinate -> String # showList :: [Coordinate] -> ShowS # | |

Eq Coordinate Source # | |

Defined in Physics.Spacetime.Flat (==) :: Coordinate -> Coordinate -> Bool # (/=) :: Coordinate -> Coordinate -> Bool # | |

type Rep Coordinate Source # | |

Defined in Physics.Spacetime.Flat type Rep Coordinate = D1 ('MetaData "Coordinate" "Physics.Spacetime.Flat" "personal-1.1.0-KcNGQtduRIs8Q6QmISu9F0" 'True) (C1 ('MetaCons "Coordinate" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Double, Double, Double, Double)))) |

# Simple operations

plus :: Coordinate -> Coordinate -> Coordinate Source #

Treat two coordinates like vectors and add them together.

`>>>`

Coordinate (1.0,2.0,0.0,0.0)`Coordinate (2, 1, 0, 0) `plus` Coordinate (-1, 1, 0, 0)`

minus :: Coordinate -> Coordinate -> Coordinate Source #

Treat two coordinates like vectors and subtract the second one from the first.

`>>>`

Coordinate (3.0,0.0,0.0,0.0)`Coordinate (2, 1, 0, 0) `minus` Coordinate (-1, 1, 0, 0)`

scale :: (Double -> Double) -> Coordinate -> Coordinate Source #

Scale each component of a coordinate with the given function.

`>>>`

Coordinate (2.0,4.0,0.0,0.0)`scale (*2) $ Coordinate (1, 2, 0, 0)`

combine :: (Double -> Double -> Double) -> Coordinate -> Coordinate -> Coordinate Source #

Combine the corresponding components of two coordinates with the given function.

`>>>`

Coordinate (2.0,-3.0,2.0,6.0)`combine (*) (Coordinate (2, 3, 1, 2)) (Coordinate (1, -1, 2, 3))`

approximates :: Coordinate -> Coordinate -> Bool Source #

Returns whether two coordinates are approximately equal to each other.

`>>>`

True`Coordinate (1, 1, 0, 0) `approximates` Coordinate (1, 1, 0, 0)`

`>>>`

False`Coordinate (1, -1, 0, 0) `approximates` Coordinate (1, 1, 0, 0)`

The threshold for being approximately equivalent is somewhat arbitrary.

# Spacetime interval

interval :: Coordinate -> Double Source #

The spacetime interval between the origin and the given coordinates.

This uses the convention where \(ds^2 = dt^2 - dx^2 - dy^2 - dz^2\).

`>>>`

3.0`interval $ Coordinate (2, 1, 0, 0)`

# Lorentz transformation

:: Double | Velocity of the new frame in the original frame. |

-> Coordinate | Coordinate in the original frame. |

-> Coordinate | Coordinate in the new frame. |

Apply the Lorentz transformation.

This transforms coordinates in an original inertial frame to those in a new inertial frame. It is assumed that the origin coincides between the two frames, and that the velocity only has an \(x\) component.

`>>>`

`let expected = Coordinate (0.414213562,0.414213562,2.0,3.0)`

`>>>`

`let actual = transform (sqrt 0.5) $ Coordinate (1, 1, 2, 3)`

`>>>`

True`actual `approximates` expected`

For reference, look up the Lorentz transformation.

:: Double | Velocity of the new fram in the original frame. |

-> Transformation V2 Double | Transformation for a two-dimensional Diagrams object. |

Returns a Lorentz transformation.

It will transform diagrams in an original inertial frame to those in a new inertial frame. It is assumed that the origin coincides between the two frames, and that the velocity only has an \(x\) component.

`>>>`

`import Diagrams.Prelude qualified as D`

`>>>`

`let c = Coordinate (2, 1, 0, 0)`

`>>>`

`let v = 0.5`

`>>>`

`let expected = vectorize2D $ transform v c`

`>>>`

`let actual = D.transform (transformation v) $ vectorize2D c`

`>>>`

True`abs (actual - expected) < 1e-5`

For reference, look up the Lorentz transformation.

# Working with Diagrams

vectorize2D :: Coordinate -> V2 Double Source #

Convert given coordinates into a two-dimensional Diagrams vector.

It will project the \(x\) coordinate to the \(x\) component and the \(t\) coordinate to the \(y\) component of the vector. The other coordinates will be ignored.

`>>>`

V2 1.0 1.0`vectorize2D $ Coordinate (1, 1, 0, 0)`

Draw axes for a spacetime diagram with default options.

Both axes will extend up to length 1 from the origin, and the lightcone will also be drawn. Units will be in Planck units, i.e., \(c = 1\).

`>>>`

`let _ = axes`

axesWith :: AxesOptions -> Diagram B Source #

Draw axes for a spacetime diagram with given options.

The horizontal axis will be for the \(x\) space coordinate, while the vertical axis will be for the \(t\) space coordinate. Units will be in Planck units, i.e., \(c = 1\).

`>>>`

`let _ = axesWith axesOptions { axesLength = 8 }`

axesOptions :: AxesOptions Source #

Default options for drawing axes.

axesLength :: AxesOptions -> Double Source #

Length of each axis. The default is 1.

`>>>`

AxesOptions {axesLength = 4.0, axesLightcone = True}`axesOptions { axesLength = 4 }`

axesLightcone :: AxesOptions -> Bool Source #

Whether to draw the lightcone. It is drawn by default.

`>>>`

AxesOptions {axesLength = 1.0, axesLightcone = False}`axesOptions { axesLightcone = False }`

data AxesOptions Source #

Stores various options for drawing axes.

#### Instances

Show AxesOptions Source # | |

Defined in Physics.Spacetime.Flat showsPrec :: Int -> AxesOptions -> ShowS # show :: AxesOptions -> String # showList :: [AxesOptions] -> ShowS # |