Created
April 7, 2021 14:02
-
-
Save jessebett/25b10be5e0dcc1683549c9b29c883d2f to your computer and use it in GitHub Desktop.
Math Compass Torus Transformation
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
## source for math political compass torus meme: | |
## https://twitter.com/jessebett/status/1379162611414138885 | |
## upcycled from torus knot fibration visualization: | |
## http://www.jessebett.com/TorusKnotFibration/torusknot.html | |
using Makie | |
using FileIO | |
compass = load("/Users/jessebett/Downloads/mathcompass.jpeg") | |
function torus(ϕ, θ , a, b) | |
R = 2; | |
r = 1; | |
x = (R - r * ((1 - a) + a * cos(ϕ * b))) * ((1 - a) * θ + sin(a * θ )) | |
y = (1 - b) * ϕ + r * sin(b * ϕ) | |
z = (R - r * cos(b * ϕ)) * -cos(a * θ ) + 1 | |
return (x,y,z) | |
end | |
function plot_torus(a,b) | |
range = -π:0.01:π | |
ϕ, θ = range,range | |
meshgrid = Iterators.product(ϕ, θ) | |
xyz = [torus(ϕ,θ, a, b) for (ϕ, θ) in meshgrid] | |
# i am bad at unpacking matrix of tuples :( | |
tx = [x for (x,y,z) in xyz] | |
ty = [y for (x,y,z) in xyz] | |
tz = [z for (x,y,z) in xyz] | |
s = Scene( | |
resolution=(1000,1000), | |
scale = (1,1,1), | |
show_axis = false, | |
shading = false | |
); | |
cam = cam3d!(s; | |
lookat=[0.,0., 0.], | |
eyeposition=[1., -1. , -1.] | |
) | |
surface!(s,tx,ty,tz, color=compass) | |
return s | |
end | |
display(plot_torus(0.,0.)) #plane | |
display(plot_torus(1.,0.)) #cylinder | |
display(plot_torus(0.,1.)) #cylinder | |
display(plot_torus(1.,1.)) #torus | |
# could animate with Makie directly but I use ffmpeg | |
# for (i,t) in enumerate(0:0.01:1) | |
# save(joinpath("anim/",lpad(i,5,"0")*".png"), plot_torus(t,t)) | |
# end | |
# for (i,t) in enumerate(1:-0.01:0) | |
# i = i+100 | |
# save(joinpath("anim/",lpad(i,5,"0")*".png"), plot_torus(t,t)) | |
# end | |
##; ffmpeg -r 1/5 -pattern_type glob -i '/anim/*.png' -c:v libx264 -vf fps=25 -pix_fmt yuv420p out.mp4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment