diff --git a/.gitignore b/.gitignore index 490a657..46b924b 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ Manifest* *.swp *.DS_Store +.vscode/* diff --git a/examples/warp.jl b/examples/warp.jl index 2a93f9a..2c94772 100644 --- a/examples/warp.jl +++ b/examples/warp.jl @@ -4,8 +4,7 @@ using WGLMakie WGLMakie.activate!(resize_to=:body) #Plots.plotly() # Parameters (TODO: make const or propogate through functions for better performance) -p = 1 -t = 0.5 +p = 2 w0 = 8 w = 2π / (p * w0) @@ -16,51 +15,53 @@ y_vals = range(-10, 10, length=1200) """ TriangleWave function """ -function f_x(x) - abs(mod(-2 * p * x, p)) +function f_x(x, period) + halfperiod = 0.5 * period + wave = mod(x, period) - halfperiod + halfperiod - abs(wave) end """ Grid function """ -function f(v) - minimum(f_x.(v)) -end +# function f(v) +# minimum(f_x.(v, p)) +# end -z = [f((x, y)) - t/2 < 0 for x in x_vals, y in y_vals] -heatmap(x_vals, y_vals, z, alpha=0.6) +# z = [f((x, y)) - t / 2 for x in x_vals, y in y_vals] +# heatmap(x_vals, y_vals, z, alpha=0.6) -function h(v) - mr = hypot(v...) - mt = atan(v[2], v[1])*w - min(f_x(mr), f_x(mt)) -end +# function h(v) +# mr = hypot(v...) +# mt = atan(v[2], v[1]) / w +# min(f_x(mr, p), f_x(mt, p)) +# end -z = [h((x, y)) - t/2 <= 0 for x in x_vals, y in y_vals] -heatmap(x_vals, y_vals, z, alpha=0.6) +# z = [h((x, y)) - t / 2 for x in x_vals, y in y_vals] +# heatmap(x_vals, y_vals, z, alpha=0.6) function j(v) - w / hypot(v...) + 1 / (w * hypot(v...)) end -z = [h((x, y))/j((x,y)) - t/2 <= 0 for x in x_vals, y in y_vals] -heatmap(x_vals, y_vals, z, alpha=0.6, title="Grid Function", xlabel="x", ylabel="y", legend=false, aspect_ratio=:equal) +# z = [h((x, y)) / j((x, y)) - t / 2 <= 0 for x in x_vals, y in y_vals] +# heatmap(x_vals, y_vals, z, alpha=0.6) using ForwardDiff -function h_g(v) - g = ForwardDiff.gradient(h, [v...]) # TODO: make this faster - hypot(g...) -end +# function h_g(v) +# g = ForwardDiff.gradient(h, [v...]) # TODO: make this faster +# hypot(g...) +# end -z = [h((x, y))/h_g((x,y)) - t/2 <= 0 for x in x_vals, y in y_vals] -heatmap(x_vals, y_vals, z, alpha=0.6, title="Grid Function", xlabel="x", ylabel="y", legend=false, aspect_ratio=:equal) +# z = [h((x, y)) / h_g((x, y)) - t / 2 for x in x_vals, y in y_vals] +# heatmap(x_vals, y_vals, z, alpha=0.6) function h_norm(v) mr = hypot(v...) - mt = atan(v[2], v[1])*w - min(f_x(mr), f_x(mt)/j(v)) + mt = atan(v[2], v[1]) / w + min(f_x(mr, p), f_x(mt, p) / j(v)) end -z = [h_norm((x, y)) - t/2 <= 0 for x in x_vals, y in y_vals] +z = [h_norm((x, y)) - t / 2 for x in x_vals, y in y_vals] heatmap(x_vals, y_vals, z, alpha=0.6)