Skip to content

Commit

Permalink
Caught an error in determining u and v in figure 1-20, and redesigned…
Browse files Browse the repository at this point in the history
… three models for accuracy.
  • Loading branch information
iamazadi committed Nov 7, 2024
1 parent 22e051a commit 92639f5
Show file tree
Hide file tree
Showing 5 changed files with 241 additions and 534 deletions.
152 changes: 66 additions & 86 deletions models/newsreport/spacetime/fig119sumofangles.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ using Porta


figuresize = (4096, 2160)
segments = 60
segments = 360
frames_number = 360
modelname = "fig119sumofangles"
M = Identity(4)
Expand All @@ -18,7 +18,9 @@ up = normalize(ℝ³(0.0, 0.0, 1.0))
arrowsize = Vec3f(0.06, 0.08, 0.1)
arrowlinewidth = 0.04
linewidth = 20
markersize = 0.05
timesign = 1
ϵ = 0.01
T = Float64(timesign)
mask = load("data/basemap_mask.png")

Expand All @@ -36,7 +38,6 @@ lscene = LScene(fig[1, 1], show_axis=false, scenekw = (lights = [pl, al], clear=
generate() = 2rand() - 1 + im * (2rand() - 1)
κ = SpinVector(generate(), generate(), timesign)
ω = SpinVector(generate(), generate(), timesign)
ϵ = 0.01
ζ = Complex(κ)
ζ′ = ζ - 1.0 / 2 * ϵ / κ.a[2]
κ = SpinVector(ζ, timesign)
Expand All @@ -54,48 +55,17 @@ generate() = 2rand() - 1 + im * (2rand() - 1)
w = (Complex+ ω) - Complex(κ)) / (Complex(ω) - Complex(κ))
@assert(imag(w) 0 || isapprox(imag(w), 0.0), "The flagpoles are not collinear: $(Complex(κ)), $(Complex(ω)), $(Complex+ ω))")

κv = 𝕍( κ)
κv′ = 𝕍( κ′)
ωv = 𝕍( ω)
ωv′ = 𝕍( ω′)
zero = 𝕍( 0.0, 0.0, 0.0, 0.0)
B = stack([vec(κv), vec(ωv), vec(zero), vec(zero)])
N = LinearAlgebra.nullspace(B)
a = 𝕍( N[begin:end, 1])
b = 𝕍( N[begin:end, 2])

a = 𝕍( LinearAlgebra.normalize(vec(a - κv - ωv)))
b = 𝕍( LinearAlgebra.normalize(vec(b - κv - ωv)))

v₁ = κv.a
v₂ = ωv.a
v₃ = a.a
v₄ = b.a

e₁ = v₁
ê₁ = normalize(e₁)
e₂ = v₂ - dot(ê₁, v₂) * ê₁
ê₂ = normalize(e₂)
e₃ = v₃ - dot(ê₁, v₃) * ê₁ - dot(ê₂, v₃) * ê₂
ê₃ = normalize(e₃)
e₄ = v₄ - dot(ê₁, v₄) * ê₁ - dot(ê₂, v₄) * ê₂ - dot(ê₃, v₄) * ê₃
ê₄ = normalize(e₄)

ê₁ = 𝕍( ê₁)
ê₂ = 𝕍( ê₂)
ê₃ = 𝕍( ê₃)
ê₄ = 𝕍( ê₄)

u = 𝕍( LinearAlgebra.normalize(rand(4)))
v = 𝕍( LinearAlgebra.normalize(rand(4)))
p = 𝕍( LinearAlgebra.normalize(vec(u + v)))
κv = 𝕍( normalize(ℝ⁴(𝕍( κ))))
κ′v = 𝕍( normalize(ℝ⁴(𝕍( κ′))))
ωv = 𝕍( normalize(ℝ⁴(𝕍( ω))))
ω′v = 𝕍( normalize(ℝ⁴(𝕍( ω′))))

northpole = Observable(Point3f(0.0, 0.0, 1.0))
tail = Observable(Point3f(0.0, 0.0, 0.0))
κtail = Observable(Point3f(0.0, 0.0, 0.0))
ωtail = Observable(Point3f(0.0, 0.0, 0.0))
κhead = Observable(Point3f(vec(project((vec(κv))))...))
ωhead = Observable(Point3f(vec(project((vec(ωv))))...))
κhead = Observable(Point3f(project((vec(κv)))))
ωhead = Observable(Point3f(project((vec(ωv)))))
ps = @lift([$κtail, $ωtail])
ns = @lift([$κhead, $ωhead])
colorants = [:red, :green]
Expand All @@ -106,9 +76,12 @@ arrows!(lscene,
align = :origin
)

circlepoints = Observable(Point3f[])
circlecolors = Observable(Int[])
circle = lines!(lscene, circlepoints, color = circlecolors, linewidth = 2linewidth, colorrange = (1, segments), colormap = :Paired_12)
circlepoints1 = Observable(Point3f[])
circlecolors1 = Observable(Int[])
circlepoints2 = Observable(Point3f[])
circlecolors2 = Observable(Int[])
lines!(lscene, circlepoints1, color = circlecolors1, linewidth = 2linewidth, colorrange = (1, segments), colormap = :Paired_12)
lines!(lscene, circlepoints2, color = circlecolors2, linewidth = 2linewidth, colorrange = (1, segments), colormap = :Dark2_8)

titles = ["N", "L", "M", "P", "Q"]
rotation = gettextrotation(lscene)
Expand All @@ -122,17 +95,17 @@ text!(lscene,
markerspace = :data
)

κflagplanematrix = makeflagplane(κv, κv′ - κv, T, segments = segments)
κflagplanecolor = Observable(fill(RGBAf(0.5, 0.5, 0.5, 0.5), segments, segments))
κflagplanematrix = makeflagplane(κv, κ′v - κv, T, segments = segments)
κflagplanecolor = Observable(fill(RGBAf(1.0, 0.0, 0.0, 0.8), segments, segments))
κflagplaneobservable = buildsurface(lscene, κflagplanematrix, κflagplanecolor, transparency = false)
ωflagplanematrix = makeflagplane(ωv, ωv′ - ωv, T, segments = segments)
ωflagplanecolor = Observable(fill(RGBAf(0.5, 0.5, 0.5, 0.5), segments, segments))
ωflagplanematrix = makeflagplane(ωv, ω′v - ωv, T, segments = segments)
ωflagplanecolor = Observable(fill(RGBAf(0.0, 1.0, 0.0, 0.8), segments, segments))
ωflagplaneobservable = buildsurface(lscene, ωflagplanematrix, ωflagplanecolor, transparency = false)

meshscatter!(lscene, northpole, markersize = 0.05, color = :black)
meshscatter!(lscene, tail, markersize = 0.05, color = :black)
meshscatter!(lscene, κtail, markersize = 0.05, color = colorants[1])
meshscatter!(lscene, ωtail, markersize = 0.05, color = colorants[2])
meshscatter!(lscene, northpole, markersize = markersize, color = :black)
meshscatter!(lscene, tail, markersize = markersize, color = :black)
meshscatter!(lscene, κtail, markersize = markersize, color = colorants[1])
meshscatter!(lscene, ωtail, markersize = markersize, color = colorants[2])

spherematrix = makesphere(M, T, compressedprojection = true, segments = segments)
sphereobservable = buildsurface(lscene, spherematrix, mask, transparency = true)
Expand All @@ -141,50 +114,57 @@ sphereobservable = buildsurface(lscene, spherematrix, mask, transparency = true)
animate(frame::Int) = begin
progress = Float64(frame / frames_number)
println("Frame: $frame, Progress: $progress")
κflagplanedirection = 𝕍( LinearAlgebra.normalize(vec(κv′ - κv)))
ωflagplanedirection = 𝕍( LinearAlgebra.normalize(vec(ωv′ - ωv)))
global u = LinearAlgebra.normalize(vec((-dot(ê₃, κflagplanedirection) * ê₃ + -dot(ê₄, κflagplanedirection) * ê₄)))
global v = LinearAlgebra.normalize(vec((-dot(ê₃, ωflagplanedirection) * ê₃ + -dot(ê₄, ωflagplanedirection) * ê₄)))
p = -𝕍(LinearAlgebra.normalize(u + v))
global p = dot(ê₃, p) * ê₃ + dot(ê₄, p) * ê₄
axis = normalize(ℝ³(vec(p)[2:4]))
M = mat4((progress * 4π, axis))
κ_transformed = M * (vec(κv))
κ′_transformed = M * (vec(κv′))
ω_transformed = M * (vec(ωv))
ω′_transformed = M * (vec(ωv′))
northpole[] = Point3f(project(M * (vec(𝕍( SpinVector(Complex(0.0), timesign))))))
spherematrix = makesphere(M, T, compressedprojection = true, segments = segments)
spintransform = SpinTransformation(progress * 2π, progress * 2π, progress * 2π)
= spintransform * κ
= spintransform * ω
_κ′ = spintransform * κ′
_ω′ = spintransform * ω′
_κv = 𝕍( normalize(ℝ⁴(𝕍( _κ))))
_κ′v = 𝕍( normalize(ℝ⁴(𝕍( _κ′))))
_ωv = 𝕍( normalize(ℝ⁴(𝕍( _ω))))
_ω′v = 𝕍( normalize(ℝ⁴(𝕍( _ω′))))
κflagplane1 = _κv
κflagplane2 = 𝕍(normalize(ℝ⁴(_κ′v - _κv)))
ωflagplane1 = _ωv
ωflagplane2 = 𝕍(normalize(ℝ⁴(_ω′v - _ωv)))
northpole[] = Point3f(project(normalize(ℝ⁴(𝕍( spintransform * SpinVector(Inf, timesign))))))
spherematrix = makesphere(spintransform, T, compressedprojection = true, segments = segments)
updatesurface!(spherematrix, sphereobservable)
= 𝕍( vec(κ_transformed))
_κ′ = 𝕍( vec(κ′_transformed))
= 𝕍( vec(ω_transformed))
_ω′ = 𝕍( vec(ω′_transformed))
κflagplanematrix = makeflagplane(_κ, 𝕍(LinearAlgebra.normalize(vec(_κ′ - _κ))), T, segments = segments)
ωflagplanematrix = makeflagplane(_ω, 𝕍(LinearAlgebra.normalize(vec(_ω′ - _ω))), T, segments = segments)
κflagplanematrix = makeflagplane(κflagplane1, κflagplane2, T, segments = segments)
ωflagplanematrix = makeflagplane(ωflagplane1, ωflagplane2, T, segments = segments)
updatesurface!(κflagplanematrix, κflagplaneobservable)
updatesurface!(ωflagplanematrix, ωflagplaneobservable)
κflagplanecolor[] = [RGBAf(1.0, 0.0, 0.0, 0.8) for i in 1:segments, j in 1:segments]
ωflagplanecolor[] = [RGBAf(0.0, 1.0, 0.0, 0.8) for i in 1:segments, j in 1:segments]
κhead[] = Point3f(project((LinearAlgebra.normalize(vec(κ_transformed - κ′_transformed)))))
ωhead[] = Point3f(project((LinearAlgebra.normalize(vec(ω_transformed - ω′_transformed)))))
κtail[] = Point3f(project(κ_transformed))
ωtail[] = Point3f(project(ω_transformed))
_circlepoints = Point3f[]
_circlecolors = Int[]
κtail[] = Point3f(project(normalize(ℝ⁴(_κv))))
ωtail[] = Point3f(project(normalize(ℝ⁴(_ωv))))
κhead[] = Point3f(project(normalize(ℝ⁴(_κ′v - _κv))))
ωhead[] = Point3f(project(normalize(ℝ⁴(_ω′v - _ωv))))
_circlepoints1 = Point3f[]
_circlecolors1 = Int[]
_circlepoints2 = Point3f[]
_circlecolors2 = Int[]
for (i, ϕ) in enumerate(collect(range(-4π, stop = 4π, length = segments)))
κζ = Complex(κ)
ωζ = Complex(ω)
ζ = κζ - ωζ
circlevector = M * (vec(𝕍( SpinVector(κζ + ϕ * ζ, timesign))))
circlepoint = Point3f(vec(project(circlevector))...)
push!(_circlepoints, circlepoint)
push!(_circlecolors, i)
circlevector = normalize(ℝ⁴(𝕍(spintransform * SpinVector(κζ + ϕ * ζ, timesign))))
circlepoint = Point3f(project(circlevector))
push!(_circlepoints1, circlepoint)
push!(_circlecolors1, i)
κζ = Complex(κ)
ωζ = Complex(ω)
center = κζ + (ωζ - κζ) / 2.0
radius = abs(ωζ - κζ) / 2.0
circlevector = normalize(ℝ⁴(𝕍(spintransform * SpinVector(center + radius * exp(im * ϕ / 4.0), timesign))))
circlepoint = Point3f(project(circlevector))
push!(_circlepoints2, circlepoint)
push!(_circlecolors2, i)
end
circlepoints[] = _circlepoints
circlecolors[] = _circlecolors
notify(circlepoints)
notify(circlecolors)
circlepoints1[] = _circlepoints1
circlecolors1[] = _circlecolors1
circlepoints2[] = _circlepoints2
circlecolors2[] = _circlecolors2
notify(circlepoints1)
notify(circlecolors1)
updatecamera!(lscene, eyeposition, lookat, up)
end

Expand Down
Loading

0 comments on commit 92639f5

Please sign in to comment.