Visualizing a 3D Vectorfield

I am trying to visualize a 3D Vectorfield like this:

Is there any Julia library capable of creating plots like these?

2 Likes

For advanced 3d visualizations I would use https://github.com/jipolanco/WriteVTK.jl together with ParaView. If you want pure Julia, take a look at https://github.com/JuliaGL/GLVisualize.jl.

4 Likes

I am not an expert on Julia, but I think you can pull it off on Windows with Paraview (by adding its bin\Lib\site-packages directory to your PYTHONPATH) through PyCall.jl (by configuring it to use your machine’s Python, preferrably Anaconda’s), and using WriteVTK.jl to write vtk and pvd files which are used by Paraview. This may seem way too hybrid for what you are looking for, but it gets the job done. I did it on my machine.

Paraview has a Python API, which you can import using “import paraview.simple” in Python, or the julia version “@pyimport paraview.simple as pv”. Good luck going through the documentation of Paraview’s API, PyCall and WriteVTK.jl!

I’d be surprised if this was very complicated to do in GLVisualize. The 3d-arrow is a cone and a cylinder, and all you do is apply a rotation, position (it looks like they’re all on concentric circles in the plane) and color mapping.

This is how you can do it:


using GLVisualize, GeometryTypes, Colors

window = glscreen()
N = 100
positions = map(x-> x .* Point3f0(3, 3, 0), (rand(Point3f0, N) - 0.5f0))
rotations = map(x-> x * rand(Float32), rand(Vec3f0, N) - 0.5f0)
# can also be something like load("arrow.obj")... You can easily find such models on the internet!
prim = Pyramid(Point3f0(0.5), 1f0, 1f0)
vis = visualize(
    (prim, positions), rotation = rotations, # position and rotations
    color_norm = GLVisualize.extrema2f0(rotations), # it uses the length to lookup the color
    color_map = [RGBA(1f0, 0f0, 0f0, 1f0), RGBA(0f0, 1f0, 0f0, 1f0)], # very simple color map. can be any array of colors
    scale = Vec3f0(0.1, 0.1, 1)
)
_view(vis)
@async renderloop(window)
4 Likes

Make sure you’re trying this on julia 0.5!

I had a look at paraview and it seemed to work ok. I will try GLVisualize aswell, thanks.

If you get it working, you might consider adding a Plots.jl recipe (even if it only works with the GLVisualize backend.)

2 Likes