-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improvements related to hemisphere and disc meshing functions
- Loading branch information
1 parent
e78d456
commit e9c3ba0
Showing
11 changed files
with
579 additions
and
172 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
using GLMakie | ||
using Random | ||
|
||
function randangle(siz) | ||
A = Matrix{Float64}(undef,siz) | ||
for i in eachindex(A) | ||
A[i] = rand()*pi*rand((-1,1)) | ||
end | ||
return A | ||
end | ||
|
||
Random.seed!(1) | ||
|
||
# Define grid | ||
size_grid = (25,25) # grid size | ||
sampleFactor = 35 # Pixel sample factor wrt grid | ||
pixelSize = 1/sampleFactor # Pixel size assuming grid has unit steps | ||
|
||
# Create grid vectors | ||
A = randangle(size_grid) # Random angles | ||
|
||
# for w = 0:1:19 | ||
# A .+= (2*pi/20) | ||
|
||
# A = pi/2 .* ones(size_grid) | ||
# for i in eachindex(A) | ||
# A[i] *= rand((-1,1)) | ||
# # println(i) | ||
# end | ||
# A[7]*=-1 | ||
|
||
Ux = cos.(A) # Unit vector x-component | ||
Uy = sin.(A) # Unit vector y-component | ||
|
||
# Initialise image | ||
size_image = (size_grid .- 1) .* sampleFactor # image size | ||
M = Matrix{Float64}(undef,size_image) # Start as undef Float64 | ||
|
||
# Pre-compute grid cell quantities | ||
xy = range(0+pixelSize/2,1-pixelSize/2,sampleFactor) # x or y coordinates within a grid cell | ||
|
||
X = [x for x in 0:sampleFactor:(size_grid[2]-1)*sampleFactor, j in 0:sampleFactor:(size_grid[1]-1)*sampleFactor]' | ||
Y = [y for i in 0:sampleFactor:(size_grid[2]-1)*sampleFactor, y in 0:sampleFactor:(size_grid[1]-1)*sampleFactor]' | ||
|
||
# ig = ceil(Int,i./sampleFactor) # Grid row index | ||
# ip = mod1(i,sampleFactor) # Cell row index | ||
|
||
# jg = ceil(Int,j./sampleFactor) # Grid column index | ||
# jp = mod1(j,sampleFactor) # Cell column index | ||
|
||
# ceil.(collect(1:1:25)./sampleFactor) | ||
|
||
function fade_perlin(a,b,t) | ||
# q = 3.0*t^3 - 2.0*t^3 # Smoothstep | ||
q = 0.5 .- 0.5.*cos.(t*pi) # Cosine | ||
# q = t # Linear | ||
|
||
# Fade function q = 6t⁵-15t⁴+10t³ | ||
# q = t^3 * (t * (6.0 * t - 15.0) + 10.0) # Perlin fade function | ||
|
||
return (1.0-q)*a + q*b | ||
end | ||
|
||
xc = [0,1,1,0] | ||
yc = [0,0,1,1] | ||
for ip in 1:sampleFactor # For each cell row | ||
for jp in 1:sampleFactor # For each cell column | ||
for ig in 1:size_grid[1]-1 # For each grid row | ||
for jg in 1:size_grid[2]-1 # For each grid column | ||
i = (ig-1)*sampleFactor + ip # Pixel row index | ||
j = (jg-1)*sampleFactor + jp # Pixel column index | ||
|
||
# Current pixel cell coordinates | ||
px = xy[jp] | ||
py = xy[ip] | ||
|
||
# Offset vector components | ||
xc1 = px # -xc[1] Offset vector 1 x | ||
xc2 = px-xc[2] # Offset vector 2 x | ||
xc3 = px-xc[3] # Offset vector 3 x | ||
xc4 = px-xc[4] # Offset vector 4 x | ||
|
||
yc1 = py # -yc[2] Offset vector 1 y | ||
yc2 = py-yc[2] # Offset vector 2 y | ||
yc3 = py-yc[3] # Offset vector 3 y | ||
yc4 = py-yc[4] # Offset vector 4 y | ||
|
||
u1x = Ux[ig ,jg] | ||
u2x = Ux[ig ,jg+1] | ||
u3x = Ux[ig+1,jg+1] | ||
u4x = Ux[ig+1,jg] | ||
|
||
u1y = Uy[ig ,jg] | ||
u2y = Uy[ig ,jg+1] | ||
u3y = Uy[ig+1,jg+1] | ||
u4y = Uy[ig+1,jg] | ||
|
||
d1 = xc1.*u1x + yc1.*u1y | ||
d2 = xc2.*u2x + yc2.*u2y | ||
d3 = xc3.*u3x + yc3.*u3y | ||
d4 = xc4.*u4x + yc4.*u4y | ||
|
||
# Interpolation | ||
# Fade function 6t⁵-15t⁴+10t³ | ||
d12 = fade_perlin(d1,d2,px) | ||
d34 = fade_perlin(d4,d3,px) | ||
d = fade_perlin(d12,d34,py) | ||
|
||
M[i,j] = d | ||
|
||
end | ||
end | ||
end | ||
end | ||
|
||
fig = Figure(size=(1500,1500)) | ||
# ax1 = Axis3(fig[1, 1], aspect = :data, xlabel = "X", ylabel = "Y", zlabel = "Z", title = "Edge angles") | ||
ax1 = Axis(fig[1, 1], aspect = DataAspect(), title = "Perlin noise",limits=(-sampleFactor,size_image[2]+sampleFactor,-sampleFactor,size_image[1]+sampleFactor) ) | ||
hm = image!(ax1, M',interpolate=false,colormap = Makie.Reverse(:Spectral),colorrange=(-0.5,0.5)) # | ||
|
||
arrows!(ax1,reduce(vcat,X), reduce(vcat,Y), reduce(vcat,Ux), reduce(vcat,Uy), arrowsize = 10, lengthscale = sampleFactor/3, color = :black, linewidth=1) | ||
|
||
Colorbar(fig[1, 2], hm) | ||
|
||
fig | ||
|
||
# save("/home/kevin/DATA/Julia/Comodo.jl/assets/img/perlin_noise_c"*string(w)*".jpg",fig,px_per_unit = 1) | ||
# save("/home/kevin/DATA/Julia/Comodo.jl/assets/img/perlin_noise_large.jpg",fig,px_per_unit = 2) | ||
|
||
# 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using Comodo | ||
using GLMakie | ||
using GeometryBasics | ||
using LinearAlgebra | ||
|
||
#= | ||
This is a demonstration of the capabilities of the `quaddisc` function which | ||
generates the faces `F` and vertices `V` for a quadrangulated disc (circle). | ||
=# | ||
|
||
# Define input parameters | ||
|
||
|
||
r = 1.0 # Radius | ||
|
||
n1 = 0 | ||
method1 = :linear | ||
F1,V1 = quaddisc(r,n1; method=method1) | ||
|
||
n2 = 1 | ||
method2 = :Catmull_Clark | ||
F2,V2 = quaddisc(r,n2; method=method2) | ||
|
||
n3 = 2 | ||
method3 = :Catmull_Clark | ||
F3,V3 = quaddisc(r,n3; method=method3) | ||
|
||
n4 = 3 | ||
method4 = :Catmull_Clark | ||
F4,V4 = quaddisc(r,n4; method=method4, orientation=:down) | ||
|
||
# Visualization | ||
fig = Figure(size=(800,800)) | ||
|
||
ax1 = Axis3(fig[1, 1], aspect = :data, xlabel = "X", ylabel = "Y", zlabel = "Z", title = "Quandrangulated disc, n=$n1, method=$method1") | ||
hp1 = poly!(ax1,GeometryBasics.Mesh(V1,F1), strokewidth=1,color=:white,shading=FastShading,transparency=false) | ||
|
||
ax2 = Axis3(fig[1, 2], aspect = :data, xlabel = "X", ylabel = "Y", zlabel = "Z", title = "Quandrangulated disc, n=$n2, method=$method2") | ||
hp2 = poly!(ax2,GeometryBasics.Mesh(V2,F2), strokewidth=1,color=:white,shading=FastShading,transparency=false) | ||
|
||
ax3 = Axis3(fig[2, 1], aspect = :data, xlabel = "X", ylabel = "Y", zlabel = "Z", title = "Quandrangulated disc, n=$n3, method=$method3") | ||
hp3 = poly!(ax3,GeometryBasics.Mesh(V3,F3), strokewidth=1,color=:white,shading=FastShading,transparency=false) | ||
|
||
ax4 = Axis3(fig[2, 2], aspect = :data, xlabel = "X", ylabel = "Y", zlabel = "Z", title = "Quandrangulated disc, n=$n4, method=$method4") | ||
hp4 = poly!(ax4,GeometryBasics.Mesh(V4,F4), strokewidth=1,color=:white,shading=FastShading,transparency=false) | ||
|
||
|
||
fig |
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,18 @@ | ||
using Comodo | ||
using GLMakie | ||
using GeometryBasics | ||
|
||
plateDim1 = [20.0,24.0] | ||
pointSpacing1 = 2.0 | ||
|
||
orientation1 = :up | ||
F1,V1 = triplate(plateDim1,pointSpacing1; orientation=orientation1) | ||
|
||
## Visualization | ||
linewidth = 1 | ||
fig = Figure(size=(1200,800)) | ||
|
||
ax1 = Axis3(fig[1, 1], aspect = :data, xlabel = "X", ylabel = "Y", zlabel = "Z", title = "Triangulated mesh plate") | ||
hp2 = poly!(ax1,GeometryBasics.Mesh(V1,F1), strokewidth=linewidth,color=:white, shading = FastShading) | ||
# normalplot(ax1,F1,V1) | ||
fig |
Oops, something went wrong.