3D visualization with camtarget and campos
Afficher commentaires plus anciens
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 commentaires
nitin harish
le 11 Sep 2018
Modifié(e) : nitin harish
le 11 Sep 2018
Did you ever get solution to your problem, do you mind posting it here ?
Petrus
le 13 Sep 2018
Javier Ros
le 26 Fév 2025
Is seems that you need a loop, at least it is mising in your code.
Réponses (0)
Catégories
En savoir plus sur Camera Views dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!