Yukterez

Equirectangular to Stereographic Projection

Jul 25th, 2020 (edited)
54
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (* |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| *)
  2. (* > raytracing.yukterez.net | Equirectangular -> Stereographic Projection Transformation *)
  3. (* |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| *)
  4.  
  5. size = 377;
  6.  
  7. xyz[{x_, y_}] := {Sin[y] Cos[x], Sin[y] Sin[x], Cos[y]}
  8. xy[{x_, y_, z_}] := {ArcTan[x, y], ArcCos[z]}
  9.  
  10. Xyz[{x_, y_, z_}, α_] := {x Cos[α]-y Sin[α], x Sin[α]+y Cos[α], z}
  11. xYz[{x_, y_, z_}, β_] := {x Cos[β]+z Sin[β], y, z Cos[β]-x Sin[β]}
  12. xyZ[{x_, y_, z_}, ψ_] := {x, y Cos[ψ]-z Sin[ψ], y Sin[ψ]+z Cos[ψ]}
  13.  
  14. rm[pic_, α_, β_, ψ_] := xy[xyZ[xYz[Xyz[xyz[pic], α], β], ψ]]
  15. RM[{x_, y_}] := rm[{x, y}, α, β, ψ]
  16.  
  17. Eq2St[{x_, y_}] := {0+ArcTan[-y, x], -2 ArcTan[2, Sqrt[x^2+y^2]]+π/2};
  18. eq2st[{x_, y_}] := RM[Eq2St[{x, y}]+{0, Pi/2}]-{0, Pi/2}
  19.  
  20. Eq = Import["http://www.yukterez.net/mw/testdisk.png"]
  21.  
  22. pic := ImageTransformation[Eq, eq2st, {size, size},
  23. DataRange -> {{-π, π}, {-π/2, π/2}},
  24. PlotRange -> {{-2, 2}, {-2, 2}}, Padding -> "Fixed", Resampling -> "Nearest"];
  25.  
  26. α=0; β=-π/2; ψ=0;
  27. pic1 = pic
  28.  
  29. α=0; β=+π/2; ψ=0;
  30. pic2 = ImageRotate[pic, π]
  31.  
  32. Export["pic1.png", pic1]
  33. Export["pic2.png", pic2]
RAW Paste Data