module Physics.Spacetime.Flat
(
Coordinate (..),
plus,
minus,
scale,
combine,
approximates,
interval,
transform,
transformation,
vectorize2D,
axes,
axesWith,
axesOptions,
axesLength,
axesLightcone,
AxesOptions,
)
where
import Diagrams.Backend.SVG
import Diagrams.Prelude hiding (interval, scale, transform)
import Diagrams.Transform.Matrix (fromMat22)
import GHC.Generics (Generic)
newtype Coordinate = Coordinate (Double, Double, Double, Double)
deriving (Coordinate -> Coordinate -> Bool
(Coordinate -> Coordinate -> Bool)
-> (Coordinate -> Coordinate -> Bool) -> Eq Coordinate
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Coordinate -> Coordinate -> Bool
== :: Coordinate -> Coordinate -> Bool
$c/= :: Coordinate -> Coordinate -> Bool
/= :: Coordinate -> Coordinate -> Bool
Eq, Int -> Coordinate -> ShowS
[Coordinate] -> ShowS
Coordinate -> String
(Int -> Coordinate -> ShowS)
-> (Coordinate -> String)
-> ([Coordinate] -> ShowS)
-> Show Coordinate
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Coordinate -> ShowS
showsPrec :: Int -> Coordinate -> ShowS
$cshow :: Coordinate -> String
show :: Coordinate -> String
$cshowList :: [Coordinate] -> ShowS
showList :: [Coordinate] -> ShowS
Show, (forall x. Coordinate -> Rep Coordinate x)
-> (forall x. Rep Coordinate x -> Coordinate) -> Generic Coordinate
forall x. Rep Coordinate x -> Coordinate
forall x. Coordinate -> Rep Coordinate x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Coordinate -> Rep Coordinate x
from :: forall x. Coordinate -> Rep Coordinate x
$cto :: forall x. Rep Coordinate x -> Coordinate
to :: forall x. Rep Coordinate x -> Coordinate
Generic)
plus :: Coordinate -> Coordinate -> Coordinate
plus :: Coordinate -> Coordinate -> Coordinate
plus = (Double -> Double -> Double)
-> Coordinate -> Coordinate -> Coordinate
combine Double -> Double -> Double
forall a. Num a => a -> a -> a
(+)
minus :: Coordinate -> Coordinate -> Coordinate
minus :: Coordinate -> Coordinate -> Coordinate
minus = (Double -> Double -> Double)
-> Coordinate -> Coordinate -> Coordinate
combine (-)
scale :: (Double -> Double) -> Coordinate -> Coordinate
scale :: (Double -> Double) -> Coordinate -> Coordinate
scale Double -> Double
f (Coordinate (Double
t, Double
x, Double
y, Double
z)) = (Double, Double, Double, Double) -> Coordinate
Coordinate (Double -> Double
f Double
t, Double -> Double
f Double
x, Double -> Double
f Double
y, Double -> Double
f Double
z)
combine :: (Double -> Double -> Double) -> Coordinate -> Coordinate -> Coordinate
combine :: (Double -> Double -> Double)
-> Coordinate -> Coordinate -> Coordinate
combine Double -> Double -> Double
f (Coordinate (Double
t, Double
x, Double
y, Double
z)) (Coordinate (Double
t', Double
x', Double
y', Double
z')) =
(Double, Double, Double, Double) -> Coordinate
Coordinate (Double -> Double -> Double
f Double
t Double
t', Double -> Double -> Double
f Double
x Double
x', Double -> Double -> Double
f Double
y Double
y', Double -> Double -> Double
f Double
z Double
z')
approximates :: Coordinate -> Coordinate -> Bool
approximates :: Coordinate -> Coordinate -> Bool
approximates (Coordinate (Double
t, Double
x, Double
y, Double
z)) (Coordinate (Double
t', Double
x', Double
y', Double
z')) =
Double
t Double -> Double -> Bool
forall {a}. (Ord a, Fractional a) => a -> a -> Bool
`closeTo` Double
t' Bool -> Bool -> Bool
&& Double
x Double -> Double -> Bool
forall {a}. (Ord a, Fractional a) => a -> a -> Bool
`closeTo` Double
x' Bool -> Bool -> Bool
&& Double
y Double -> Double -> Bool
forall {a}. (Ord a, Fractional a) => a -> a -> Bool
`closeTo` Double
y' Bool -> Bool -> Bool
&& Double
z Double -> Double -> Bool
forall {a}. (Ord a, Fractional a) => a -> a -> Bool
`closeTo` Double
z'
where
closeTo :: a -> a -> Bool
closeTo a
a a
b = a -> a
forall a. Num a => a -> a
abs (a
a a -> a -> a
forall a. Num a => a -> a -> a
- a
b) a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< a
1e-5
interval :: Coordinate -> Double
interval :: Coordinate -> Double
interval (Coordinate (Double
t, Double
x, Double
y, Double
z)) = Double
t Double -> Double -> Double
forall a. Floating a => a -> a -> a
** Double
2 Double -> Double -> Double
forall a. Num a => a -> a -> a
- Double
x Double -> Double -> Double
forall a. Floating a => a -> a -> a
** Double
2 Double -> Double -> Double
forall a. Num a => a -> a -> a
- Double
y Double -> Double -> Double
forall a. Floating a => a -> a -> a
** Double
2 Double -> Double -> Double
forall a. Num a => a -> a -> a
- Double
z Double -> Double -> Double
forall a. Floating a => a -> a -> a
** Double
2
transform ::
Double ->
Coordinate ->
Coordinate
transform :: Double -> Coordinate -> Coordinate
transform Double
v (Coordinate (Double
t, Double
x, Double
y, Double
z)) = (Double, Double, Double, Double) -> Coordinate
Coordinate (Double
t', Double
x', Double
y', Double
z')
where
gamma :: Double
gamma = Double
1 Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/ Double -> Double
forall a. Floating a => a -> a
sqrt (Double
1 Double -> Double -> Double
forall a. Num a => a -> a -> a
- Double
v Double -> Double -> Double
forall a. Floating a => a -> a -> a
** Double
2)
t' :: Double
t' = Double
gamma Double -> Double -> Double
forall a. Num a => a -> a -> a
* (Double
t Double -> Double -> Double
forall a. Num a => a -> a -> a
- Double
v Double -> Double -> Double
forall a. Num a => a -> a -> a
* Double
x)
x' :: Double
x' = Double
gamma Double -> Double -> Double
forall a. Num a => a -> a -> a
* (Double
x Double -> Double -> Double
forall a. Num a => a -> a -> a
- Double
v Double -> Double -> Double
forall a. Num a => a -> a -> a
* Double
t)
y' :: Double
y' = Double
y
z' :: Double
z' = Double
z
transformation ::
Double ->
Transformation V2 Double
transformation :: Double -> Transformation V2 Double
transformation Double
v = M22 Double -> V2 Double -> Transformation V2 Double
forall n. Floating n => M22 n -> V2 n -> T2 n
fromMat22 M22 Double
matrix (Double -> Double -> V2 Double
forall a. a -> a -> V2 a
V2 Double
0 Double
0)
where
gamma :: Double
gamma = Double
1 Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/ Double -> Double
forall a. Floating a => a -> a
sqrt (Double
1 Double -> Double -> Double
forall a. Num a => a -> a -> a
- Double
v Double -> Double -> Double
forall a. Floating a => a -> a -> a
** Double
2)
matrix :: M22 Double
matrix = V2 Double -> V2 Double -> M22 Double
forall a. a -> a -> V2 a
V2 (Double -> Double -> V2 Double
forall a. a -> a -> V2 a
V2 Double
gamma (-Double
gamma Double -> Double -> Double
forall a. Num a => a -> a -> a
* Double
v)) (Double -> Double -> V2 Double
forall a. a -> a -> V2 a
V2 (-Double
gamma Double -> Double -> Double
forall a. Num a => a -> a -> a
* Double
v) Double
gamma)
vectorize2D :: Coordinate -> V2 Double
vectorize2D :: Coordinate -> V2 Double
vectorize2D (Coordinate (Double
t, Double
x, Double
_, Double
_)) = (Double, Double) -> V2 Double
forall n. (n, n) -> V2 n
r2 (Double
x, Double
t)
data AxesOptions = AxesOptions
{
AxesOptions -> Double
axesLength :: Double,
AxesOptions -> Bool
axesLightcone :: Bool
}
deriving (Int -> AxesOptions -> ShowS
[AxesOptions] -> ShowS
AxesOptions -> String
(Int -> AxesOptions -> ShowS)
-> (AxesOptions -> String)
-> ([AxesOptions] -> ShowS)
-> Show AxesOptions
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> AxesOptions -> ShowS
showsPrec :: Int -> AxesOptions -> ShowS
$cshow :: AxesOptions -> String
show :: AxesOptions -> String
$cshowList :: [AxesOptions] -> ShowS
showList :: [AxesOptions] -> ShowS
Show)
axesOptions :: AxesOptions
axesOptions :: AxesOptions
axesOptions = AxesOptions {axesLength :: Double
axesLength = Double
1.0, axesLightcone :: Bool
axesLightcone = Bool
True}
axes :: Diagram B
axes :: Diagram B
axes = AxesOptions -> Diagram B
axesWith AxesOptions
axesOptions
axesWith :: AxesOptions -> Diagram B
axesWith :: AxesOptions -> Diagram B
axesWith AxesOptions {Double
axesLength :: AxesOptions -> Double
axesLength :: Double
axesLength, Bool
axesLightcone :: AxesOptions -> Bool
axesLightcone :: Bool
axesLightcone} =
QDiagram B V2 Double Any
xAxis QDiagram B V2 Double Any
-> QDiagram B V2 Double Any -> QDiagram B V2 Double Any
forall a. Semigroup a => a -> a -> a
<> QDiagram B V2 Double Any
tAxis QDiagram B V2 Double Any
-> QDiagram B V2 Double Any -> QDiagram B V2 Double Any
forall a. Semigroup a => a -> a -> a
<> QDiagram B V2 Double Any
lightCone
where
xAxis :: QDiagram B V2 Double Any
xAxis = (-Double
PrevDim
(Point
(V (QDiagram B V2 Double Any)) (N (QDiagram B V2 Double Any)))
axesLength PrevDim
(Point
(V (QDiagram B V2 Double Any)) (N (QDiagram B V2 Double Any)))
-> FinalCoord
(Point
(V (QDiagram B V2 Double Any)) (N (QDiagram B V2 Double Any)))
-> Point
(V (QDiagram B V2 Double Any)) (N (QDiagram B V2 Double Any))
forall c. Coordinates c => PrevDim c -> FinalCoord c -> c
^& FinalCoord
(V (QDiagram B V2 Double Any) (N (QDiagram B V2 Double Any)))
FinalCoord
(Point
(V (QDiagram B V2 Double Any)) (N (QDiagram B V2 Double Any)))
0) Point (V (QDiagram B V2 Double Any)) (N (QDiagram B V2 Double Any))
-> Point
(V (QDiagram B V2 Double Any)) (N (QDiagram B V2 Double Any))
-> QDiagram B V2 Double Any
forall t (v :: * -> *) n.
(V t ~ v, N t ~ n, TrailLike t) =>
Point v n -> Point v n -> t
~~ (Double
PrevDim
(Point
(V (QDiagram B V2 Double Any)) (N (QDiagram B V2 Double Any)))
axesLength PrevDim
(Point
(V (QDiagram B V2 Double Any)) (N (QDiagram B V2 Double Any)))
-> FinalCoord
(Point
(V (QDiagram B V2 Double Any)) (N (QDiagram B V2 Double Any)))
-> Point
(V (QDiagram B V2 Double Any)) (N (QDiagram B V2 Double Any))
forall c. Coordinates c => PrevDim c -> FinalCoord c -> c
^& FinalCoord
(V (QDiagram B V2 Double Any) (N (QDiagram B V2 Double Any)))
FinalCoord
(Point
(V (QDiagram B V2 Double Any)) (N (QDiagram B V2 Double Any)))
0)
tAxis :: QDiagram B V2 Double Any
tAxis = (Double
PrevDim (Point V2 Double)
0 PrevDim (Point V2 Double)
-> FinalCoord (Point V2 Double) -> Point V2 Double
forall c. Coordinates c => PrevDim c -> FinalCoord c -> c
^& (-Double
axesLength)) Point V2 Double -> Point V2 Double -> QDiagram B V2 Double Any
forall n b.
(TypeableFloat n, Renderable (Path V2 n) b) =>
Point V2 n -> Point V2 n -> QDiagram b V2 n Any
`arrowBetween` (Double
PrevDim (Point V2 Double)
0 PrevDim (Point V2 Double)
-> FinalCoord (Point V2 Double) -> Point V2 Double
forall c. Coordinates c => PrevDim c -> FinalCoord c -> c
^& Double
FinalCoord (Point V2 Double)
axesLength)
lightCone :: QDiagram B V2 Double Any
lightCone
| Bool
axesLightcone =
(QDiagram B V2 Double Any
forwardEdge QDiagram B V2 Double Any
-> QDiagram B V2 Double Any -> QDiagram B V2 Double Any
forall a. Semigroup a => a -> a -> a
<> QDiagram B V2 Double Any
backwardEdge)
# opacity 0.75
# dashingN [0.01, 0.02] 0
# lw ultraThin
| Bool
otherwise = QDiagram B V2 Double Any
forall a. Monoid a => a
mempty
where
forwardEdge :: QDiagram B V2 Double Any
forwardEdge = Point (V (QDiagram B V2 Double Any)) (N (QDiagram B V2 Double Any))
lowerLeftCorner Point (V (QDiagram B V2 Double Any)) (N (QDiagram B V2 Double Any))
-> Point
(V (QDiagram B V2 Double Any)) (N (QDiagram B V2 Double Any))
-> QDiagram B V2 Double Any
forall t (v :: * -> *) n.
(V t ~ v, N t ~ n, TrailLike t) =>
Point v n -> Point v n -> t
~~ Point (V (QDiagram B V2 Double Any)) (N (QDiagram B V2 Double Any))
upperRightCorner
backwardEdge :: QDiagram B V2 Double Any
backwardEdge = QDiagram B V2 Double Any -> QDiagram B V2 Double Any
forall (v :: * -> *) n t.
(InSpace v n t, R1 v, Transformable t) =>
t -> t
reflectX QDiagram B V2 Double Any
forwardEdge
lowerLeftCorner :: Point (V (QDiagram B V2 Double Any)) (N (QDiagram B V2 Double Any))
lowerLeftCorner = (-Double
axesLength) PrevDim
(Point
(V (QDiagram B V2 Double Any)) (N (QDiagram B V2 Double Any)))
-> FinalCoord
(Point
(V (QDiagram B V2 Double Any)) (N (QDiagram B V2 Double Any)))
-> Point
(V (QDiagram B V2 Double Any)) (N (QDiagram B V2 Double Any))
forall c. Coordinates c => PrevDim c -> FinalCoord c -> c
^& (-Double
axesLength)
upperRightCorner :: Point (V (QDiagram B V2 Double Any)) (N (QDiagram B V2 Double Any))
upperRightCorner = Double
PrevDim
(Point
(V (QDiagram B V2 Double Any)) (N (QDiagram B V2 Double Any)))
axesLength PrevDim
(Point
(V (QDiagram B V2 Double Any)) (N (QDiagram B V2 Double Any)))
-> FinalCoord
(Point
(V (QDiagram B V2 Double Any)) (N (QDiagram B V2 Double Any)))
-> Point
(V (QDiagram B V2 Double Any)) (N (QDiagram B V2 Double Any))
forall c. Coordinates c => PrevDim c -> FinalCoord c -> c
^& Double
FinalCoord
(Point
(V (QDiagram B V2 Double Any)) (N (QDiagram B V2 Double Any)))
axesLength