-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #58 from JuliaGeometry/sjk/warp2
sjk/warp2
- Loading branch information
Showing
16 changed files
with
175 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
using Descartes | ||
using StaticArrays | ||
using ForwardDiff | ||
using HCubature | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,49 @@ | ||
using Revise | ||
using Descartes: Descartes, TriangleWave, FRep, Grid | ||
using WGLMakie | ||
|
||
using Descartes: Descartes, TriangleWave, FRep, Grid, PolarWarp, Cuboid | ||
using WGLMakie, Makie | ||
using CoordinateTransformations | ||
using StaticArrays | ||
using ForwardDiff | ||
using LinearAlgebra | ||
t = TriangleWave(2.) | ||
|
||
x = 1:0.1:10 | ||
y = [FRep(t, e) for e in x] | ||
|
||
lines(x,y) | ||
|
||
g = Grid(1.0) | ||
g = Grid(Square([10, 10]), 1.0) | ||
|
||
x_vals = 1:0.1:10 | ||
y_vals = 1:0.1:10 | ||
x_vals = -10:0.1:10 | ||
y_vals = -10:0.1:10 | ||
|
||
# basic Grid | ||
z = [FRep(g, (x, y)) for x in x_vals, y in y_vals] | ||
extrema(z) | ||
heatmap(x_vals, y_vals, z, alpha=0.6) | ||
|
||
|
||
# Apply warp | ||
g_polar = PolarWarp(g, 8) | ||
|
||
z = [min(FRep(g_polar, (x, y))...) for x in x_vals, y in y_vals] | ||
extrema(z) | ||
heatmap(x_vals, y_vals, z, alpha=0.6) | ||
|
||
|
||
|
||
polar_f(v) = FRep(g_polar, v) | ||
polar_f([1,2]) | ||
polar_f_min(v) = min(polar_f(v)...) | ||
polar_f_min([1,2]) | ||
|
||
polar_f_jac(v) = ForwardDiff.jacobian(polar_f, v) | ||
z = [polar_f_jac([x, y]) for x in x_vals, y in y_vals] | ||
|
||
# TODO : Correction factor | ||
exper1(v) = norm(inv(polar_f_jac(v))*ForwardDiff.gradient(polar_f_min, v)) | ||
|
||
z = [exper1([x, y]) for x in x_vals, y in y_vals] | ||
extrema(z) | ||
heatmap(x_vals, y_vals, z, alpha=0.6) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# https://www.desmos.com/calculator/mcjscmo6fq | ||
|
||
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 | ||
w0 = 8 | ||
|
||
w = 2π / (p * w0) | ||
|
||
x_vals = range(-10, 10, length=1200) | ||
y_vals = range(-10, 10, length=1200) | ||
|
||
""" | ||
TriangleWave function | ||
""" | ||
function f_x(x) | ||
abs(mod(-2 * p * x, p)) | ||
end | ||
|
||
""" | ||
Grid function | ||
""" | ||
function f(v) | ||
minimum(f_x.(v)) | ||
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) | ||
|
||
function h(v) | ||
mr = hypot(v...) | ||
mt = atan(v[2], v[1])*w | ||
min(f_x(mr), f_x(mt)) | ||
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) | ||
|
||
function j(v) | ||
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) | ||
|
||
using ForwardDiff | ||
|
||
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) | ||
|
||
function h_norm(v) | ||
mr = hypot(v...) | ||
mt = atan(v[2], v[1])*w | ||
min(f_x(mr), f_x(mt)/j(v)) | ||
end | ||
|
||
z = [h_norm((x, y)) - t/2 <= 0 for x in x_vals, y in y_vals] | ||
heatmap(x_vals, y_vals, z, alpha=0.6) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
@testset "examples" begin | ||
dir = "../examples" | ||
files = [ #"csg.jl", | ||
"example001.jl", | ||
#"piping.jl", | ||
"radiused_union.jl", | ||
"fea.jl", | ||
"2d.jl"] | ||
for file in files | ||
@testset "$file" begin | ||
include("$dir/$file") | ||
end | ||
end | ||
#dir = "../examples" | ||
#dir = "../examples" | ||
#files = [ "csg.jl", | ||
# "example001.jl", | ||
# #"piping.jl", | ||
# "radiused_union.jl", | ||
# "2d.jl"] | ||
#for file in files | ||
# @testset "$file" begin | ||
# include("$dir/$file") | ||
# end | ||
#end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters