Skip to content

Raytracing a Level Set geometry ​

A level set geometry is defined by a constraint equations f(x,y,z)=0. We will ray trace an example parabaloid geometry in this example as a simple geometric jet model.

julia
using Krang
import CairoMakie as GLMk
using GeometryBasics
using FileIO

Lets create a camera with a screen of 20Mx20M at a resolution of 200x200 pixels for a high spin black hole.

julia
metric = Krang.Kerr(0.9) # Kerr metric with a spin of 0.99
θo = 89 / 180 * π # Inclination angle of the observer
ρmax = 20.0 # Horizontal and Vertical extent of the screen
sze = 200 # Resolution of the screen is sze x sze

camera = Krang.SlowLightIntensityCamera(metric, θo, -ρmax, ρmax, -ρmax, ρmax, sze)
SlowLightIntensityCamera{Krang.SlowLightIntensityScreen{Float64, Matrix{Float64}, Matrix{ComplexF64}}}(Kerr{Float64}(1.0, 0.9), Krang.SlowLightIntensityScreen{Float64, Matrix{Float64}, Matrix{ComplexF64}}((-20.0, 20.0), (-20.0, 20.0), Kerr{Float64}(1.0, 0.9), 1.5533430342749532, [-20.0 -20.0 … -20.0 -20.0; -19.798994974874372 -19.798994974874372 … -19.798994974874372 -19.798994974874372; … ; 19.798994974874372 19.798994974874372 … 19.798994974874372 19.798994974874372; 20.0 20.0 … 20.0 20.0], [-20.0 -19.798994974874372 … 19.798994974874372 20.0; -20.0 -19.798994974874372 … 19.798994974874372 20.0; … ; -20.0 -19.798994974874372 … 19.798994974874372 20.0; -20.0 -19.798994974874372 … 19.798994974874372 20.0], ComplexF64[-29.18861423266478 - 3.3537505426307734e-17im -29.046130530864428 - 3.396586734596297e-17im … -29.046130530864428 - 3.396586734596297e-17im -29.18861423266478 - 3.3537505426307734e-17im; -29.04667442643992 - 5.620168701301023e-17im -28.90346553307467 - 9.108138668858363e-17im … -28.90346553307467 - 9.108138668858363e-17im -29.04667442643992 - 5.620168701301023e-17im; … ; -29.128240280734634 - 3.883554476108743e-17im -28.985826372226512 - 9.181453318037082e-17im … -28.985826372226512 - 9.181453318037082e-17im -29.128240280734634 - 3.883554476108743e-17im; -29.270222058152335 - 6.430986063777065e-17im -29.128525886907646 - 3.909143401421816e-17im … -29.128525886907646 - 3.909143401421816e-17im -29.270222058152335 - 6.430986063777065e-17im], ComplexF64[0.24263747362939725 + 1.5063696195576235e-15im 0.23992633257421048 + 1.5139444112783999e-15im … 0.23992633257421048 + 1.5139444112783999e-15im 0.24263747362939725 + 1.5063696195576235e-15im; 0.2455036370048358 + 2.523263671940176e-15im 0.24278493795946687 + 4.05772960860807e-15im … 0.24278493795946687 + 4.05772960860807e-15im 0.2455036370048358 + 2.523263671940176e-15im; … ; 0.21837642095379906 + 1.5135074544035291e-15im 0.21578789375665863 + 3.5494387932541685e-15im … 0.21578789375665863 + 3.5494387932541685e-15im 0.21837642095379906 + 1.5135074544035291e-15im; 0.21591257735939706 + 2.5098773115862156e-15im 0.21333429615515165 + 1.5134916299043445e-15im … 0.21333429615515165 + 1.5134916299043445e-15im 0.21591257735939706 + 2.5098773115862156e-15im], ComplexF64[1.6782502513720612 - 1.5168879528449595e-15im 1.6801710889137595 - 1.5246539812970533e-15im … 1.6801710889137595 - 1.5246539812970533e-15im 1.6782502513720612 - 1.5168879528449595e-15im; 1.675479817403053 - 2.5409933970922264e-15im 1.677401030435787 - 4.0866178352476894e-15im … 1.677401030435787 - 4.0866178352476894e-15im 1.675479817403053 - 2.5409933970922264e-15im; … ; 1.8853709532469747 - 1.5271231514258879e-15im 1.889058637744217 - 3.581840758314369e-15im … 1.889058637744217 - 3.581840758314369e-15im 1.8853709532469747 - 1.5271231514258879e-15im; 1.8877216183686318 - 2.5322909829522873e-15im 1.891386614223805 - 1.5272047153813409e-15im … 1.891386614223805 - 1.5272047153813409e-15im 1.8877216183686318 - 2.5322909829522873e-15im], ComplexF64[27.26772650766332 + 4.4055838713643797e-17im 27.126033109376458 + 4.4675437364616284e-17im … 27.126033109376458 + 4.4675437364616284e-17im 27.26772650766332 + 4.4055838713643797e-17im; 27.125690972032032 + 7.393141216506084e-17im 26.983279564679414 + 1.199696133282037e-16im … 26.983279564679414 + 1.199696133282037e-16im 27.125690972032032 + 7.393141216506084e-17im; … ; 27.024492906533858 + 5.2451241783446053e-17im 26.880979840725637 + 1.242164982405707e-16im … 26.880979840725637 + 1.242164982405707e-16im 27.024492906533858 + 5.2451241783446053e-17im; 27.166587862424308 + 8.67235320038425e-17im 27.02380497652869 + 5.280451949121466e-17im … 27.02380497652869 + 5.280451949121466e-17im 27.166587862424308 + 8.67235320038425e-17im], [0.058204597315845714 0.058511821788351674 … 0.058511821788351674 0.058204597315845714; 0.0585127014633823 0.05882477803349028 … 0.05882477803349028 0.0585127014633823; … ; 0.058798845891308196 0.059117179023065056 … 0.059117179023065056 0.058798845891308196; 0.05848754042092072 0.058800886402035776 … 0.058800886402035776 0.05848754042092072], [0.11640919463169143 0.11702364357670335 … 0.11702364357670335 0.11640919463169143; 0.1170254029267646 0.11764955606698056 … 0.11764955606698056 0.1170254029267646; … ; 0.11759769178261639 0.11823435804613011 … 0.11823435804613011 0.11759769178261639; 0.11697508084184144 0.11760177280407155 … 0.11760177280407155 0.11697508084184144], [2.842209106471304 2.829149170490956 … 2.829149170490956 2.842209106471304; 2.862808515454489 2.8495247188392203 … 2.8495247188392203 2.862808515454489; … ; -1.920214553000808 -1.9101643225947529 … -1.9101643225947529 -1.920214553000808; -1.913062716282651 -1.9031518069893167 … -1.9031518069893167 -1.913062716282651], [16.713342732597273 16.62807951011331 … 16.62807951011331 16.713342732597273; 16.53112101059466 16.44584142166788 … 16.44584142166788 16.53112101059466; … ; 35.132340998083016 34.982143433903644 … 34.982143433903644 35.132340998083016; 35.235421819378814 35.086295583384015 … 35.086295583384015 35.235421819378814], [-2.688591622641137 -2.6838951582860844 … -2.6838951582860844 -2.688591622641137; -2.6836041693004997 -2.6788597952709825 … -2.6788597952709825 -2.6836041693004997; … ; -2.6902914744750386 -2.685628082722018 … -2.685628082722018 -2.6902914744750386; -2.695221515280359 -2.6906044419738793 … -2.6906044419738793 -2.695221515280359], [-22.121051943139634 -22.009265777746894 … -22.009265777746894 -22.121051943139634; -22.009244028105655 -21.896887621703385 … -21.896887621703385 -22.009244028105655; … ; -21.992007567214067 -21.879378826697454 … -21.879378826697454 -21.992007567214067; -22.10390761986673 -21.99185337797063 … -21.99185337797063 -22.10390761986673], [-0.2387349764137514 -0.2380889068451399 … -0.2380889068451399 -0.2387349764137514; -0.24278256678878965 -0.2421163298926147 … -0.2421163298926147 -0.24278256678878965; … ; -0.12936412407862471 -0.12898605055029197 … -0.12898605055029197 -0.12936412407862471; -0.12801015873373897 -0.12764086166099955 … -0.12764086166099955 -0.12801015873373897], [-0.05085597634204857 -0.05102660372461329 … -0.05102660372461329 -0.05085597634204857; -0.05124865853146545 -0.05142307125008812 … -0.05142307125008812 -0.05124865853146545; … ; -0.04308885306472323 -0.04318985552253317 … -0.04318985552253317 -0.04308885306472323; -0.04278961036898225 -0.04288860240841204 … -0.04288860240841204 -0.04278961036898225], [0.0008725762173162971 0.0008814330369263448 … 0.0008814330369263448 0.0008725762173162971; 0.0008725779887162478 0.0008814348628136626 … 0.0008814348628136626 0.0008725779887162478; … ; 0.0008725779887162478 0.0008814348628136626 … 0.0008814348628136626 0.0008725779887162478; 0.0008725762173162971 0.0008814330369263448 … 0.0008814330369263448 0.0008725762173162971], [0.11108611795829751 0.11164630991360983 … 0.11164630991360983 0.11108611795829751; 0.11164544500936019 0.11221418496573957 … 0.11221418496573957 0.11164544500936019; … ; 0.11164544500936019 0.11221418496573957 … 0.11221418496573957 0.11164544500936019; 0.11108611795829751 0.11164630991360983 … 0.11164630991360983 0.11108611795829751], [0.0008726648323428316 0.0008815225514868534 … 0.0008815225514868534 0.0008726648323428316; 0.0008726666038507306 0.0008815243774853934 … 0.0008815243774853934 0.0008726666038507306; … ; 0.0008726666038507306 0.0008815243774853934 … 0.0008815243774853934 0.0008726666038507306; 0.0008726648323428316 0.0008815225514868534 … 0.0008815225514868534 0.0008726648323428316], [0.15715977986553964 0.1571606342452944 … 0.1571606342452944 0.15715977986553964; 0.15875559314344626 0.1587564693564807 … 0.1587564693564807 0.15875559314344626; … ; 0.15875559314344626 0.1587564693564807 … 0.1587564693564807 0.15875559314344626; 0.15715977986553964 0.1571606342452944 … 0.1571606342452944 0.15715977986553964], [8.859881610420455e-8 8.949825967173883e-8 … 8.949825967173883e-8 8.859881610420455e-8; 8.85989269332578e-8 8.949832750094565e-8 … 8.949832750094565e-8 8.85989269332578e-8; … ; 8.85989269332578e-8 8.949832750094565e-8 … 8.949832750094565e-8 8.85989269332578e-8; 8.859881610420455e-8 8.949825967173883e-8 … 8.949825967173883e-8 8.859881610420455e-8], [0.02779227837990401 0.027650748247351434 … 0.027650748247351434 0.02779227837990401; 0.02821414139636405 0.0280747591454878 … 0.0280747591454878 0.02821414139636405; … ; 0.02821414139636405 0.0280747591454878 … 0.0280747591454878 0.02821414139636405; 0.02779227837990401 0.027650748247351434 … 0.027650748247351434 0.02779227837990401], [400.1215878811236 392.12178989622424 … 392.12178989622424 400.1215878811236; 400.119151250731 392.11935326583165 … 392.11935326583165 400.119151250731; … ; 400.119151250731 392.11935326583165 … 392.11935326583165 400.119151250731; 400.1215878811236 392.12178989622424 … 392.12178989622424 400.1215878811236], [19.996953903127825 19.996953903127825 … 19.996953903127825 19.996953903127825; 19.795979492041113 19.795979492041113 … 19.795979492041113 19.795979492041113; … ; -19.795979492041113 -19.795979492041113 … -19.795979492041113 -19.795979492041113; -19.996953903127825 -19.996953903127825 … -19.996953903127825 -19.996953903127825]), (Inf, 1.5533430342749532))

We will define a parabaloid geometry to the set of all points satisfied by the equation cos⁡(θ)=1−(r/rh)n.

julia
struct Parabaloid{T} <: Krang.AbstractLevelSetGeometry{T}
    rh::T
    index::T
end
function (geometry::Parabaloid)(x, y, z)
    r = sqrt(x^2 + y^2 + z^2)
    return 1 - (r / geometry.rh)^geometry.index * (1 - z / r)
end

The jet will be emit a constant intensity whose physics we define in the XMaterial.

We are ignoring relativistic effects in this example.

julia
struct XMaterial <: Krang.AbstractMaterial end
function (mat::XMaterial)(pix, intersection)
    return 1.0
end

We will ray trace the geometry and plot the image.

julia
parabaloid = Parabaloid(Krang.horizon(metric), 1.0)

fig = GLMk.Figure();
ax = GLMk.Axis(fig[1, 1], aspect = 1)


intersections = raytrace(camera, Krang.Mesh(parabaloid, XMaterial()), res = 1_00);

And plot the image with GLMakie,

julia
GLMk.heatmap!(ax, intersections, colormap = :afmhot);
fig

GLMk.save("geometric_jet.png", fig)


This page was generated using Literate.jl.