3D volume plot for spherical coordinate grid points

The second r, θ and ϕ are denoting values of the cell interface locations along x1/x2/x3-direction which i think is equivalent to vertices positions.

What should i do for mapping colors to vertices in my case? How can i learn to do mapping to vertices?

You can learn more by reading the recipe that is called as fallback for grids:

In your case you have a 3D RectilinearGrid, so you will enter into the mesh falllback:

The mesh fallback will probably call this method:

which in turn calls an utility function that restarts the process with a single concatenated object:

I don’t think it is easy to provide what you need in 3D, but if Makie.jl provides a special function in this particular case, we could add a special branch for it in our first fallback above, avoiding the mesh fallback.

@sdanisch can tell you for sure if that is possible or not with the current release of Makie.jl

1 Like

@raman_kumar if your grid is not too big, you can convert it into a SimpleMesh and call viz. This method will support colors on elements or vertices:

r = Float32[1.677044, 1.8385518, 2.0156136, 2.2097273, 2.4225352, 2.6558375, 2.911608, 3.1920104, 3.499417, 3.8364286, 4.205896, 4.6109447, 5.055002, 5.5418243, 6.0755296, 6.660634, 7.3020864, 8.005314]
θ = Float32[0.049087387, 0.14726216, 0.24543692, 0.3436117]
ϕ = Float32[0.19634955, 0.5890486, 0.9817477, 1.3744467, 1.7671459, 2.1598449, 2.552544, 2.9452431, 3.3379421, 3.7306414, 4.12334, 4.5160394, 4.9087386, 5.3014374, 5.6941366, 6.086836]

g = RectilinearGrid{𝔼,typeof(Spherical(0,0,0))}(r, θ, ϕ)

m = convert(SimpleMesh, g)

viz(m, color=1:nvertices(m))

1 Like

Nevermind, I think the result doesn’t change because these are 3D geometries and we didn’t implement the color-by-vertex case yet either.

1 Like

Can you summarize what exactly?
Seems like I need to read through the entire thread to understand what’s being wanted here.

using Meshes, CoordRefSystems ,GLMakie

r =  Float32[1.6, 1.754088, 1.9230156, 2.1082115, 2.311243, 2.5338273, 2.7778475, 3.0453684, 3.3386526, 3.6601818, 4.012676, 4.3991165, 4.8227735, 5.287231, 5.7964177, 6.354642, 6.9666257, 7.637547, 8.373081]
θ =  Float32[0.0, 0.09817477, 0.19634955, 0.2945243, 0.3926991]
ϕ =  Float32[0.0, 0.3926991, 0.7853982, 1.1780972, 1.5707964, 1.9634954, 2.3561945, 2.7488935, 3.1415927, 3.5342917, 3.9269907, 4.3196898, 4.712389, 5.105088, 5.497787, 5.8904862, 6.2831855]

g = RectilinearGrid{𝔼,typeof(Spherical(0,0,0))}(r, θ, ϕ)
nrho = rand(1152)
viz(g, color=nrho)

This above code assigns color to nelements but i want to assign color to nvertices. Here r, θ and ϕ are denoting values of interface locations along x1/x2/x3-direction

Simon, he is trying to ask if Makie provides a function to visualize grids that are not “cubes” and color the elements of the grid with colors at the vertices.

Something like this?


using GeometryBasics, GLMakie
meshes = map(CartesianIndices((10, 10, 10))) do i 
    # Create a sphere with radius 0.5 at position (i, 0, 0)
    sphere = Sphere(Point3f(Tuple(i)), 0.5)
    # Create a mesh from the sphere
    points = decompose(Point3f, sphere)
    faces = decompose(GLTriangleFace, sphere)
    colors = rand(Float32, length(points))
    mesh = GeometryBasics.Mesh(points, faces; color = colors)
    # Plot the mesh
end
mesh(vec(meshes))

No, a mesh where geometries themselves are 3D. In your example you are discretizing the Sphere as 2D triangles.

Can we visualize a single Hexahedron with colors on vertices and get the volume within with interpolated colors? Or do we need to do it at a faces (quadrangles) level?

@ffreyer Any Idea on it