Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ Manifest*

*.swp
*.DS_Store
.vscode/*
57 changes: 29 additions & 28 deletions examples/warp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)