Rotating plot around line in Makie

Hey amazing Makie people!

I would like to rotate a heatmap around a given line in a 3d scene.
So far rotate!(plt, qrotation(Vec3([0, 1, 0]), pi)) works great but I can only rotate against the x,y,z axis. How can I rotate with respect to a translated axis?

I already found this question about rotating plots but there was no solution for my problem

Thanks!

@theogf , the working solution for CairoMakie was to turn it into a png and then place it within another plot :cry:

Here is the code:

using GLMakie

f, ax, pl = barplot(rand(5), bar_labels=:y, figure=(resolution=(500, 500),))
hideydecorations!(ax)
hidespines!(ax, :t, :r, :l)
hidexdecorations!(ax, ticks=false)
tightlimits!(ax)
f
img = Makie.colorbuffer(ax.scene)

f, ax, pl = scatter(rand(Point2f, 100), axis=(aspect = DataAspect(),))
impl = image!(ax, 0..1, 0..1, rotr90(img))
display(f)

rotate!(impl, -0.25pi)
translate!(impl, 0.5, 1.2, 0)
xlims!(ax, 0, 2)
ylims!(ax, 0, 2)

Code from Simon Danisch

That will not work for me as I need to make an animation :cry:
Here is something I attempted

half_axis = Vec3([0, -1, 0])
val = 10
for i in 1:nsteps
            m_ϵ = qrotation(half_axis, i *  π / nsteps)
            translate!(plt2, Vec3([-val, 0, 0]))
            rotate!(Accum, plt2, m_ϵ)
            translate!(Accum, plt2, Vec3([val, 0, 0]))
            sleep(0.01)
end

But this just makes the plot jumps around everywhere :laughing:

I don’t think the transformation system lets pick an origin for a rotation. But you can build your own model matrix to translate the heatmap, then rotate it, then translate it back:

model = 
    Makie.translationmatrix(axis_origin) *
    Makie.rotationmatrix(qrotation(axis, angle)) *
    Makie.translationmatrix(-axis_origin)
plt.model[] = model

(If that doesn’t work you may need to pass the model matrix when you create the plot. I vaguely remember some issue there.)

Alternatively you can define your heatmap so that it rotates the way you want (i.e. heatmap(-1…1, -1…1, data) if you want to rotate around the center) and then rotate and translate with the normal system. The order of operations there is always rotation first, scale and translation after.

I ended up centering the heatmap as you proposed @ffreyer, but this stops me from adding more nice stuff unfortunately :slight_smile:

I also saw one can pass a transformation so by doing A (x - v) + v I guess this could be somehow done