Skip to content

Instantly share code, notes, and snippets.

@Nyrox
Created July 30, 2019 09:59
Show Gist options
  • Save Nyrox/dca545f26e000fb7334e043d71f0aa4c to your computer and use it in GitHub Desktop.
Save Nyrox/dca545f26e000fb7334e043d71f0aa4c to your computer and use it in GitHub Desktop.
using Makie
using AbstractPlotting
scene = Scene()
scene = mesh(Sphere(Point3f0(0), 0.9f0), transparency=true, alpha=0.05)
function cosine_weighted_sample_hemisphere()
r1 = rand()
r2 = rand()
theta = acos(sqrt(r1))
phi = 2π * r2
Point3f0(sin(theta)cos(phi), cos(theta), sin(theta)sin(phi))
end
function plot_directions!(scene, N, generator)
dirs = []
for i in 1:N
push!(dirs, generator())
end
arrows!(
scene,
fill(Point3f0(0), N),
dirs,
arrowcolor=:red,
arrowsize=0.1,
linecolor=:red
)
end
plot_directions!(scene, 100, cosine_weighted_sample_hemisphere)
scene
@asinghvi17
Copy link

Just made a PR to add this to MakieGallery.jl!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment