Getting current scene azimuth and elevation

Makie 0.20 has added a method update_cam!(scene, azimuth, elevation). Is there an easy way to go in the other direction, to get the azimuth and elevation values corresponding to the current scene configuration?

These values are readily available in an Axis3 but I’m working with an LScene.

For context: In Matlab I often do the following:

% get a good viewing angle with the mouse
% then retrieve this config with:
[az, el] = view
% tweak the values of `az` and `el` manually or programatically
% then apply new values with:
view(az, el)

I’d like to do the same with Makie.

You can calculate those from l.scene.camera_controls.eyeposition[] and l.scene.camera_controls.lookat[] as those are what that method sets:

1 Like

Thanks! I guess I cannot assume this particular value Vec3f(-st * cp, -st * sp, ct) of upvector for the general case, but we can easily invert these spherical coordinates (with theta defined as the angle from the xy plane) based on lookat and eyeposition:

v = normalize(cam.eyeposition[] - cam.lookat[])
phi = atan(v[2], v[1])  # azimuth
theta = asin(v[3])      # elevation (between -π/2 and π/2)

It could be nice to have a helper function for that in Makie?