Rotate 3D axis camera perspective about arbitrary direction vector

8 visualizzazioni (ultimi 30 giorni)
I have the 3D graphic below. I would like to rotate the camera perspective about the axis represented by the pink dashed arrow until I am viewing the blue arc edge-on. The rotate 3D tool seems limited in the range of camera motion that it allows, and is not letting me do this. Is there a programmatic substitute that will let me get arbitrary camera perspectives specified, for example, using a 3x3 rotation matrix?
  1 Commento
Bruno Luong
Bruno Luong il 13 Nov 2018
Modificato: Bruno Luong il 13 Nov 2018
Actually I don't understand whn you say there is a limitation of range.
According to this page the CameraTarget/CameraPosition can be anything, so the looking direction is not limited. Similar to CameraUpVector, it look like you can twist the camera projection plane by arbitrary angle.
This parameters seem to be directly related to intrinsic Tait–Bryan convention and you can control through using rotation matrix/quaternion by proper conversion.

Accedi per commentare.

Risposta accettata

Bruno Luong
Bruno Luong il 13 Nov 2018
Modificato: Bruno Luong il 13 Nov 2018
Here is a demo to show using Camera parameters, I also put the rotation matrix R in comment. I find MATLAB parameters more intuitive to use than the rotation matrix.
s = peaks;
x = linspace(-10,10,size(s,2));
y = linspace(-10,10,size(s,1));
figure(1)
clf
ax = axes();
surf(ax,x,y,s);
axis(ax,'equal');
t = 0;
dt = 0.05;
while true
t = t+dt;
az = (2*pi/2)*t; % azimuth/yaw, linear, round period 2s
el = 0.5*sin(t*(2*pi/5)); % elevation/pitch osc varies (-0.5,0.5) radian (28 deg) for a period of 5s
roll = 0.2*sin(t*(2*pi/3)); % twist/roll, osc varies (-0.2,0.2) radian (11.5 deg) for a period of 3s
r = 80; % camera distance
caz = cos(az);
saz = sin(az);
cel = cos(el);
sel = sin(el);
crl = cos(roll);
srl = sin(roll);
xc = caz*cel;
yc = saz*cel;
zc = sel;
c = [xc;yc;zc];
h = [-saz; caz; 0];
v = [-caz*sel; -saz*sel; cel];
u = cos(roll)*v+sin(roll)*h;
%% Camera (3 x 3) Rotation matrix R is
% p = sin(roll)*v-cos(roll)*h;
% R = [c,u,p];
set(ax,...
'CameraPosition',r*c,... % Add CameraTarget if not 0
'CameraUpVector',u);
pause(dt);
end
  2 Commenti
Matt J
Matt J il 19 Nov 2018
Modificato: Matt J il 20 Nov 2018
Setting the 'CameraUpVector' property was key. When using the interactive rotation tool
it always snaps back to [0,0,1] for some reason...
Bruno Luong
Bruno Luong il 19 Nov 2018
Odd, may be somewhere there is a high level graphic command that resets the view?

Accedi per commentare.

Più risposte (1)

Bruno Luong
Bruno Luong il 12 Nov 2018
  1 Commento
Matt J
Matt J il 12 Nov 2018
Modificato: Matt J il 12 Nov 2018
No, hgtransform will rotate the graphic, not the camera perspective. I want the axes to rotate as well.

Accedi per commentare.

Tag

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by