Created
July 20, 2018 14:05
-
-
Save caeus/cc3c03e80dd4b3662cd69b9ec753899f to your computer and use it in GitHub Desktop.
Relativity transformer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Plane = (Double, Double) | |
type Matrix = (Plane, Plane) | |
type TaggedEvents = Map[String, Plane] | |
private val sin45 = Math.sqrt(0.5) | |
private val matrixMinus45 = ((sin45, sin45), (-sin45, sin45)) | |
private val matrixPlus45 = ((sin45, -sin45), (sin45, sin45)) | |
def transform(events: TaggedEvents, from: String): TaggedEvents = { | |
val reference = events(from) | |
val spacetimeT = multiplyV(matrixMinus45, reference) | |
println("ref="+spacetimeT) | |
val lambda = Math.sqrt(spacetimeT._2 / spacetimeT._1) | |
println("lamda="+lambda) | |
println(multiplyM(matrixMinus45,matrixPlus45)) | |
val lorenzMatrix = ((lambda, 0d), (0d, 1.0 / lambda)) | |
val ultimateMatrix = multiplyM(multiplyM(matrixMinus45, lorenzMatrix), matrixPlus45) | |
events.mapValues { | |
plane => | |
multiplyV(matrixPlus45,multiplyV(lorenzMatrix,multiplyV(matrixMinus45, plane))) | |
} | |
} | |
def multiplyM(matrix1: Matrix, matrix2: Matrix): Matrix = { | |
((matrix1._1._1 * matrix2._1._1 + matrix1._1._2 * matrix2._2._1, | |
matrix1._1._1 * matrix2._1._2 + matrix1._1._2 * matrix2._2._2), | |
(matrix1._2._1 * matrix2._1._1 + matrix1._2._2 * matrix2._2._1, | |
matrix1._2._1 * matrix2._1._2 + matrix1._2._2 * matrix2._2._2)) | |
} | |
def multiplyV(matrix: Matrix, plane: Plane): Plane = { | |
( | |
matrix._1._1 * plane._1 + matrix._1._2 * plane._2, | |
matrix._2._1 * plane._1 + matrix._2._2 * plane._2 | |
) | |
} | |
println(transform(Map("normal"->(3,4)),"normal")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment