Skip to content

Instantly share code, notes, and snippets.

@j-fu
Created September 21, 2020 21:26
Show Gist options
  • Save j-fu/a5c4a23557e1799510109a66d99d3528 to your computer and use it in GitHub Desktop.
Save j-fu/a5c4a23557e1799510109a66d99d3528 to your computer and use it in GitHub Desktop.
A Pluto notebook with MWE
### A Pluto.jl notebook ###
# v0.11.14
using Markdown
using InteractiveUtils
# ╔═╡ fc86a902-f46d-11ea-15ac-d3a989493e19
begin
using Pkg
Pkg.add("MeshCat")
Pkg.add("ColorTypes")
Pkg.add("GeometryBasics")
Pkg.add("IJulia")
Pkg.add("PyPlot")
end
# ╔═╡ 9ef87d96-f414-11ea-2262-dfb9eea7187f
using MeshCat, GeometryBasics, ColorTypes,IJulia,PyPlot
# ╔═╡ b4ab4486-fc48-11ea-0ab0-75dc08a4c24f
points=[0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0; 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.3 0.3 0.3 0.3 0.3 0.3 0.3 0.3 0.3 0.3 0.3 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.6 0.6 0.6 0.6 0.6 0.6 0.6 0.6 0.6 0.6 0.6 0.7 0.7 0.7 0.7 0.7 0.7 0.7 0.7 0.7 0.7 0.7 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.8 0.9 0.9 0.9 0.9 0.9 0.9 0.9 0.9 0.9 0.9 0.9 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0]
# ╔═╡ c4ca2ec0-fc48-11ea-0be8-0989b504ca63
faces=[1 13 2 14 3 15 4 16 5 17 6 18 7 19 8 20 9 21 10 22 12 24 13 25 14 26 15 27 16 28 17 29 18 30 19 31 20 32 21 33 23 35 24 36 25 37 26 38 27 39 28 40 29 41 30 42 31 43 32 44 34 46 35 47 36 48 37 49 38 50 39 51 40 52 41 53 42 54 43 55 45 57 46 58 47 59 48 60 49 61 50 62 51 63 52 64 53 65 54 66 56 68 57 69 58 70 59 71 60 72 61 73 62 74 63 75 64 76 65 77 67 79 68 80 69 81 70 82 71 83 72 84 73 85 74 86 75 87 76 88 78 90 79 91 80 92 81 93 82 94 83 95 84 96 85 97 86 98 87 99 89 101 90 102 91 103 92 104 93 105 94 106 95 107 96 108 97 109 98 110 100 112 101 113 102 114 103 115 104 116 105 117 106 118 107 119 108 120 109 121; 2 12 3 13 4 14 5 15 6 16 7 17 8 18 9 19 10 20 11 21 13 23 14 24 15 25 16 26 17 27 18 28 19 29 20 30 21 31 22 32 24 34 25 35 26 36 27 37 28 38 29 39 30 40 31 41 32 42 33 43 35 45 36 46 37 47 38 48 39 49 40 50 41 51 42 52 43 53 44 54 46 56 47 57 48 58 49 59 50 60 51 61 52 62 53 63 54 64 55 65 57 67 58 68 59 69 60 70 61 71 62 72 63 73 64 74 65 75 66 76 68 78 69 79 70 80 71 81 72 82 73 83 74 84 75 85 76 86 77 87 79 89 80 90 81 91 82 92 83 93 84 94 85 95 86 96 87 97 88 98 90 100 91 101 92 102 93 103 94 104 95 105 96 106 97 107 98 108 99 109 101 111 102 112 103 113 104 114 105 115 106 116 107 117 108 118 109 119 110 120; 13 1 14 2 15 3 16 4 17 5 18 6 19 7 20 8 21 9 22 10 24 12 25 13 26 14 27 15 28 16 29 17 30 18 31 19 32 20 33 21 35 23 36 24 37 25 38 26 39 27 40 28 41 29 42 30 43 31 44 32 46 34 47 35 48 36 49 37 50 38 51 39 52 40 53 41 54 42 55 43 57 45 58 46 59 47 60 48 61 49 62 50 63 51 64 52 65 53 66 54 68 56 69 57 70 58 71 59 72 60 73 61 74 62 75 63 76 64 77 65 79 67 80 68 81 69 82 70 83 71 84 72 85 73 86 74 87 75 88 76 90 78 91 79 92 80 93 81 94 82 95 83 96 84 97 85 98 86 99 87 101 89 102 90 103 91 104 92 105 93 106 94 107 95 108 96 109 97 110 98 112 100 113 101 114 102 115 103 116 104 117 105 118 106 119 107 120 108 121 109]
# ╔═╡ 073a017e-fc4c-11ea-09b6-0f0c52675c87
func=Base.map( (x,y) -> Float32(sin(5*x)*cos(5*y)),points[1,:],points[2,:]);
# ╔═╡ 21fb13b0-fc4f-11ea-3840-4d5691e693a7
md"""
Check correctness of data by plotting with PyPlot:
"""
# ╔═╡ 91950f92-fc4e-11ea-162e-a5fb218e157e
begin
fig=PyPlot.figure(1,figsize=(2,2))
PyPlot.tricontourf(points[1,:], points[2,:],transpose(faces.-1),func)
fig
end
# ╔═╡ 080174c4-fc48-11ea-2456-ed34ecd70223
function make_mesh(points, faces, func)
npoints=size(points,2)
nfaces=size(faces,2)
meshpoints=Vector{Point3f0}(undef,npoints)
for i=1:npoints
meshpoints[i]=Point3f0(points[1,i],points[2,i],func[i])
end
meshfaces=Vector{GLTriangleFace}(undef,nfaces)
for i=1:nfaces
meshfaces[i]=TriangleFace(faces[1,i],faces[2,i],faces[3,i])
end
GeometryBasics.Mesh(meshpoints,meshfaces)
end
# ╔═╡ 670d1116-fc49-11ea-3334-b72bcdb3b80c
mesh=make_mesh(points,faces,func)
# ╔═╡ b7622c74-f414-11ea-0572-b5a85078884e
vis = Visualizer()
# ╔═╡ edcc51ea-f414-11ea-3ee5-b7b74c7e8913
IJuliaCell(vis)
# ╔═╡ 13d7b10e-f415-11ea-0de5-194b56044342
setobject!(vis, mesh,MeshPhongMaterial(color=RGBA{Float32}(1.0, 0.0,0.0,1.0)))
# ╔═╡ Cell order:
# ╠═fc86a902-f46d-11ea-15ac-d3a989493e19
# ╠═9ef87d96-f414-11ea-2262-dfb9eea7187f
# ╟─b4ab4486-fc48-11ea-0ab0-75dc08a4c24f
# ╟─c4ca2ec0-fc48-11ea-0be8-0989b504ca63
# ╠═073a017e-fc4c-11ea-09b6-0f0c52675c87
# ╟─21fb13b0-fc4f-11ea-3840-4d5691e693a7
# ╟─91950f92-fc4e-11ea-162e-a5fb218e157e
# ╠═080174c4-fc48-11ea-2456-ed34ecd70223
# ╠═670d1116-fc49-11ea-3334-b72bcdb3b80c
# ╠═b7622c74-f414-11ea-0572-b5a85078884e
# ╟─edcc51ea-f414-11ea-3ee5-b7b74c7e8913
# ╠═13d7b10e-f415-11ea-0de5-194b56044342
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment