2

I have a quiver3 plot on MATLAB with the code and plot as following, and I would like the lines to be color-variant as they approach the center point (which is cyan blue), so that I could visulize their distances from the center. Any idea how could I do that? Thanks so much!

hold on;
grid on;
scatter3(frame_cur.xyz_cam(1,:),frame_cur.xyz_cam(2,:),frame_cur.xyz_cam(3,:),'MarkerFaceColor',[0 .75 .75]);
quiver3(frameGT_cur.xyz_cam(1,:),                  ...
        frameGT_cur.xyz_cam(2,:),                  ...
        frameGT_cur.xyz_cam(3,:),                  ...
        C(1,:)-frame_cur.xyz_cam(1,:),     ...
        C(2,:)-frame_cur.xyz_cam(2,:),     ...
        C(3,:)-frame_cur.xyz_cam(3,:),     ...
        0,'b','ShowArrowHead','off');*

enter image description here

jiayi
  • 89
  • 10

1 Answers1

4

it's not using quiver3 but the result is close to what you requested. this answer is inspired by this answer.

I used surf with the name-value arguments 'FaceColor','none','EdgeColor','interp' to create lines with interpolating color:

% generate random 3D points
n = 10;
x = 2*rand(n,1)-1;
y = 2*rand(n,1)-1;
z = 2*rand(n,1)-1;
% the color is the distance of each point
c = sqrt(x.^2 + y.^2 + z.^2); 
% plot the points
scatter3(x,y,z,40,c,'filled');
hold on
% add zeros (the center point) between points
xx = [zeros(1,numel(x));x(:)'];xx = xx(:);
yy = [zeros(1,numel(y));y(:)'];yy = yy(:);
zz = [zeros(1,numel(z));z(:)'];zz = zz(:);
cc = [zeros(1,numel(c));c(:)'];cc = cc(:);
% plot the lines
h = surf([xx,xx],[yy,yy],[zz,zz],[cc,cc],...
    'FaceColor','none','EdgeColor','interp','LineWidth',1);
colorbar;

enter image description here

user2999345
  • 4,195
  • 1
  • 13
  • 20