@@ -10,7 +10,7 @@ function viz(sys::Union{FSPanelSystem,NKPanelSystem};kwargs...)
1010 # add free surface
1111 x,y,z = xyζ(sys)
1212 ζmax = maximum(abs, z); @. z[abs(z)< ζmax/ 20 ] = 0
13- surface!(x,y,z;shading = NoShading, colormap = :balance, colorrange = (- ζmax,ζmax))
13+ surface!(x,y,z' ; colormap = :balance, clims = (-ζmax,ζmax))
1414end
1515
1616# Generate mesh from Table data
@@ -20,23 +20,27 @@ function viz(panels::Union{Table,PanelTree}, values=panels.dA; vectors=panels.n,
2020 cmap = cgrad(colormap)
2121 color = [cmap[(v - clims[1]) / (clims[2] - clims[1])] for v in values]
2222 tricolor = eltype(panels.kernel)==QuadKernel ? mapreduce(c->[c;c],vcat,color) : color
23-
23+
2424 # Collect all vertices
2525 xs = Float32[]
2626 ys = Float32[]
2727 zs = Float32[]
2828 connections_i = Int[]
2929 connections_j = Int[]
3030 connections_k = Int[]
31-
31+
3232 for panel in panels
3333 addtri!(xs,ys,zs,connections_i,connections_j,connections_k,panel.verts,panel.kernel)
3434 end
35-
35+
3636 # Invisible plot for colorbar
3737 cx,cy,cz = components(panels.x)
38- p1 = scatter3d(cx,cy,cz;markersize= 0 ,fill_z= values,clims,c= colormap,
39- colorbar= true ,colorbar_title= label,legend= false ,xlabel= " x" ,ylabel= " y" ,zlabel= " z" ,kwargs... )
38+ scatter3d(cx,cy,cz;markersize=0,fill_z=values,clims,c=colormap,
39+ colorbar=true,colorbar_title=label,legend=false)
40+
41+ # Main plot
42+ mesh3d!(xs, ys, zs; color = tricolor, linewidth=0,
43+ connections=(connections_i, connections_j, connections_k), kwargs...)
4044
4145 # Add normal vectors if provided
4246 if !isnothing(vectors)
@@ -45,30 +49,20 @@ function viz(panels::Union{Table,PanelTree}, values=panels.dA; vectors=panels.n,
4549 quiver!(cx, cy, cz; color=:grey, quiver=(nx, ny, nz), arrow=:closed, linewidth=1.5)
4650 end
4751
48- # Main plot
49- mesh3d!(xs, ys, zs; color = tricolor, linewidth= 0 ,
50- connections= (connections_i, connections_j, connections_k))
51-
52- # Data ranges
53- xmin,xmax = extrema(xs)
54- ymin,ymax = extrema(ys)
55- zmin,zmax = extrema(zs)
52+ # set plot limits, labels
53+ (xmin,xmax),(ymin,ymax),(zmin,zmax) = extrema.((xs,ys,zs))
54+ cxm,cym,czm = (xmin+xmax)/2,(ymin+ymax)/2,(zmin+zmax)/2
5655 Δ = maximum((xmax-xmin, ymax-ymin, zmax-zmin))
57- cxm = (xmin+ xmax)/ 2
58- cym = (ymin+ ymax)/ 2
59- czm = (zmin+ zmax)/ 2
60- xlims!(p1, cxm- Δ/ 2 , cxm+ Δ/ 2 )
61- ylims!(p1, cym- Δ/ 2 , cym+ Δ/ 2 )
62- zlims!(p1, czm- Δ/ 2 , czm+ Δ/ 2 )
63- display(p1)
56+ plot!(xlabel="x",ylabel="y",zlabel="z",
57+ xlims=(cxm-Δ/2, cxm+Δ/2),ylims=(cym-Δ/2, cym+Δ/2),zlims=(czm-Δ/2, czm+Δ/2))
6458end
6559addtri!(x,y,z,i,j,k,verts,::QuadKernel) = (
6660 addtri!(x,y,z,i,j,k,verts[1:3]); addtri!(x,y,z,i,j,k,verts[[1,3,4]]))
6761function addtri!(x,y,z,i,j,k,verts,args...)
6862 for v in verts
6963 push!(x, v[1]); push!(y, v[2]); push!(z, v[3])
7064 end
71-
65+
7266 # Connections for this triangle (0-indexed)
7367 base = length(x)-3
7468 push!(i, base); push!(j, base + 1); push!(k, base + 2)
0 commit comments