Rotate 3D axis camera perspective about arbitrary direction vector

7 ビュー (過去 30 日間)
Matt J
Matt J 2018 年 11 月 12 日
編集済み: Matt J 2018 年 11 月 20 日
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 件のコメント
Bruno Luong
Bruno Luong 2018 年 11 月 13 日
編集済み: Bruno Luong 2018 年 11 月 13 日
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.

サインインしてコメントする。

採用された回答

Bruno Luong
Bruno Luong 2018 年 11 月 13 日
編集済み: Bruno Luong 2018 年 11 月 13 日
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 件のコメント
Matt J
Matt J 2018 年 11 月 19 日
編集済み: Matt J 2018 年 11 月 20 日
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 2018 年 11 月 19 日
Odd, may be somewhere there is a high level graphic command that resets the view?

サインインしてコメントする。

その他の回答 (1 件)

Bruno Luong
Bruno Luong 2018 年 11 月 12 日
  1 件のコメント
Matt J
Matt J 2018 年 11 月 12 日
編集済み: Matt J 2018 年 11 月 12 日
No, hgtransform will rotate the graphic, not the camera perspective. I want the axes to rotate as well.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCamera Views についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by