3D visualization with camtarget and campos
이전 댓글 표시
Dear,
I cannot solve this simple issue: I would like to perform a 3D plot tracking a point (let's say a cross) behind the track.
I tried campos and camtarget using a pre-existing example as follows:
clear all; clc; close all;
tf = 1;
dt = .01;
% Create a figure and a surface plot
fig = figure('position',[00 00 1000 700]);hold on;
centerfig
ax = axes;
[X,Y,Z] = peaks(50);
Z = Z/max(max(Z))*.5;
surf(ax,X,Y,Z);hold on;
% plot the trajectory
k=1;
for t = 0:dt:tf
xt(k) = 2.0 * sin(2.0*3.14*0.2*t);
yt(k) = 2.0 * cos(2.0*3.14*0.2*t);
zt(k) = interp2(X,Y,Z,xt(k),yt(k),'cubic')+.2;
k=k+1;
end
plot3(xt,yt,zt,'+','color','m');
% Set the camera viewing projection and angle
camproj('perspective');
camva(10);
t=20*dt;
% Camera position along the track
xp = 2.0 * sin(2.0*3.14*0.2*t);
yp = 2.0 * cos(2.0*3.14*0.2*t);
zp = interp2(X,Y,Z,xp,yp,'cubic')+.2;
% Camera target : 5 steps ahead
xnext = 2.0 * sin(2.0*3.14*0.2*(t+5*dt));
ynext = 2.0 * cos(2.0*3.14*0.2*(t+5*dt));
znext = interp2(X,Y,Z,xnext,ynext,'cubic')+.2;
axis equal
axis off
grid off
box off
campos([xp,yp,zp]);
camtarget([xnext;ynext;znext]);
drawnow
What I get is this:

The view does target the desired location but the point of view does not correspond to a point belonging to the track (5 steps before). What is wrong is my use of campos and camtarget?
Thanks, Petrus
댓글 수: 3
nitin harish
2018년 9월 11일
편집: nitin harish
2018년 9월 11일
Did you ever get solution to your problem, do you mind posting it here ?
Petrus
2018년 9월 13일
Javier Ros
2025년 2월 26일
Is seems that you need a loop, at least it is mising in your code.
답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Lighting, Transparency, and Shading에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!