personal-1.1.0: Personal web site for Yoo Chung
CopyrightCopyright (C) 2023 Yoo Chung
LicenseAll rights reserved
Maintainerweb@chungyc.org
Safe HaskellSafe-Inferred
LanguageGHC2021

Physics.Spacetime.Flat

Description

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

Coordinates

newtype Coordinate Source #

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

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

Constructors

Coordinate (Double, Double, Double, Double) 

Instances

Instances details
Generic Coordinate Source # 
Instance details

Defined in Physics.Spacetime.Flat

Associated Types

type Rep Coordinate :: Type -> Type #

Show Coordinate Source # 
Instance details

Defined in Physics.Spacetime.Flat

Eq Coordinate Source # 
Instance details

Defined in Physics.Spacetime.Flat

type Rep Coordinate Source # 
Instance details

Defined in Physics.Spacetime.Flat

type Rep Coordinate = D1 ('MetaData "Coordinate" "Physics.Spacetime.Flat" "personal-1.1.0-8nBFZ8AtVDqCZ0rfQbr8Bq" '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 (2, 1, 0, 0) `plus` Coordinate (-1, 1, 0, 0)
Coordinate (1.0,2.0,0.0,0.0)

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

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

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

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

Scale each component of a coordinate with the given function.

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

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

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

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

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

Returns whether two coordinates are approximately equal to each other.

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

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\).

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

Lorentz transformation

transform Source #

Arguments

:: 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)
>>> actual `approximates` expected
True

For reference, look up the Lorentz transformation.

transformation Source #

Arguments

:: 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
>>> abs (actual - expected) < 1e-5
True

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.

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

axes :: Diagram B Source #

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 }
AxesOptions {axesLength = 4.0, axesLightcone = True}

axesLightcone :: AxesOptions -> Bool Source #

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

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

data AxesOptions Source #

Stores various options for drawing axes.

Instances

Instances details
Show AxesOptions Source # 
Instance details

Defined in Physics.Spacetime.Flat