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 CenterFile Exchange에서 Camera Views에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by