如何使用正交投影绘制 3D 参数曲线?

How to 3D plot a parametric curve WITH orthographic projections?

如何在 3D 图的内壁上生成具有正交投影的参数曲线的 3D 图,如 this video?

所示

我可以使用 plot3 函数生成曲线的 3D 图,但我不知道如何在立方体的内壁上创建蓝色正交投影......和红色虚线。

P.S.
此外,如何生成 3 个单独的 "Coordinate Functions" 图(上图中未显示但在视频中显示)......以及如何在动画期间将它们同步在一起?

嗯,写到这里花了很多时间。

clear;clc;close all
t = 0:0.01:6;

x = cos(5*t);
y = sin(5*t);
z = t;

%for x,y,z as as general function of t
xmin = min(x);
xmax = max(x);

ymin = min(y);
ymax = max(y);

zmin = min(z);
zmax = max(z);

orangeColorRGB = [0.8500 0.3250 0.0980];

%3D plot
plot3DSubplot = subplot(3,2,[1 3 5]);
view(3)
grid on
title('Parametric curve in R^3')
xlabel('x(t)')
ylabel('y(t)')
zlabel('z(t)')

xyProjectionOffset = -0.5;
xzProjectionOffset = 1.5;
yzProjectionOffset = 1.5;

xlim([xmin max(xmax, yzProjectionOffset)])
ylim([ymin max(ymax, xzProjectionOffset)])
zlim([min(zmin ,xyProjectionOffset) zmax])

curve3D_marker = animatedline(plot3DSubplot,x(1),y(1),z(1),'Marker','o','Color','magenta'); %marker in 3D
curve3D = animatedline(plot3DSubplot, x(1),y(1),z(1),'Color','magenta','LineStyle','-','LineWidth',2); %3D curve

curve3D_projectedToXY = animatedline(plot3DSubplot,x(1),y(1),xyProjectionOffset,'Color','blue','LineStyle','-','LineWidth',2); %projection on xy
curve3D_projectionStraightLineToXY = animatedline(plot3DSubplot,x(1),y(1),z(1),'Color',orangeColorRGB,'LineStyle','--','LineWidth',2); %projection on xy 

curve3D_projectedToXZ = animatedline(plot3DSubplot,x(1),xzProjectionOffset,z(1),'Color','blue','LineStyle','-','LineWidth',2); %projection on xz
curve3D_projectionStraightLineToXZ = animatedline(plot3DSubplot,x(1),y(1),z(1),'Color',orangeColorRGB,'LineStyle','--','LineWidth',2); %projection on xy 

curve3D_projectedToYZ = animatedline(plot3DSubplot,yzProjectionOffset,y(1),z(1),'Color','blue','LineStyle','-','LineWidth',2); %projection on yz
curve3D_projectionStraightLineToYZ = animatedline(plot3DSubplot,x(1),y(1),z(1),'Color',orangeColorRGB,'LineStyle','--','LineWidth',2); %projection on xy 

%x plot
xPlot = subplot(3,2,2);
grid on
title('Coordinates')
ylabel('cos(5t)')
xlim([t(1) t(end)])
ylim([xmin xmax])
xCoordinate = animatedline(xPlot,t(1),x(1),'Color','blue');
xCoordinate_projectedValue = animatedline(xPlot,t(1),x(1),'Color',orangeColorRGB,'LineStyle','--');
xCoordinateMarker = animatedline(xPlot,t(1),x(1),'Color','blue','Marker','o');

%y plot
yPlot = subplot(3,2,4);
grid on
ylabel('sin(5t)')
xlim([t(1) t(end)])
ylim([ymin ymax])
yCoordinate = animatedline(yPlot,t(1),y(1),'Color','blue');
yCoordinate_projectedValue = animatedline(yPlot,t(1),y(1),'Color',orangeColorRGB,'LineStyle','--');
yCoordinateMarker = animatedline(yPlot,t(1),y(1),'Color','blue','Marker','o');

%z plot
zPlot = subplot(3,2,6);
grid on
ylabel('t')
xlim([t(1) t(end)])
ylim([zmin zmax])
zCoordinate = animatedline(zPlot,t(1),z(1),'Color','blue');
zCoordinate_projectedValue = animatedline(zPlot,t(1),z(1),'Color',orangeColorRGB,'LineStyle','--');
zCoordinateMarker = animatedline(zPlot,t(1),z(1),'Color','blue','Marker','o');

for i=2:length(t)

    % 3D plot & projections
    addpoints(curve3D,x(i),y(i),z(i))
    clearpoints(curve3D_marker)
    addpoints(curve3D_marker,x(i),y(i),z(i))

    %XY projection
    addpoints(curve3D_projectedToXY,x(i),y(i),xyProjectionOffset)
    clearpoints(curve3D_projectionStraightLineToXY)
    addpoints(curve3D_projectionStraightLineToXY,[x(i) x(i)],[y(i) y(i)],[xyProjectionOffset z(i)])

    %XZ projection
    addpoints(curve3D_projectedToXZ,x(i),xzProjectionOffset,z(i))
    clearpoints(curve3D_projectionStraightLineToXZ)
    addpoints(curve3D_projectionStraightLineToXZ,[x(i) x(i)],[xzProjectionOffset y(i)],[z(i) z(i)])

    %YZ projection
    addpoints(curve3D_projectedToYZ,1.5,y(i),z(i))
    clearpoints(curve3D_projectionStraightLineToYZ)
    addpoints(curve3D_projectionStraightLineToYZ,[yzProjectionOffset x(i)],[y(i) y(i)],[z(i) z(i)])

    %2D x plot
    addpoints(xCoordinate,t(i),x(i))
    clearpoints(xCoordinate_projectedValue)
    addpoints(xCoordinate_projectedValue,[t(1) t(i)],[x(i) x(i)])
    clearpoints(xCoordinateMarker)
    addpoints(xCoordinateMarker,t(i),x(i))

    %2D y plot
    addpoints(yCoordinate,t(i),y(i))
    clearpoints(yCoordinate_projectedValue)
    addpoints(yCoordinate_projectedValue,[t(1) t(i)],[y(i) y(i)])
    clearpoints(yCoordinateMarker)
    addpoints(yCoordinateMarker,t(i),y(i))

    %2D z plot
    addpoints(zCoordinate,t(i),z(i))
    clearpoints(zCoordinate_projectedValue)
    addpoints(zCoordinate_projectedValue,[t(1) t(i)],[z(i) z(i)])
    clearpoints(zCoordinateMarker)
    addpoints(zCoordinateMarker,t(i),z(i))

    drawnow
end

外for-loop:

  1. 定义你的子图。

  2. 以某种 object-oriented 的方式定义您的台词。用 animatedline 定义行 包括他们的 properties (颜色、线宽等)。

  3. 定义带有 animatedline 的行,目的是仅使用标记。

里面for-loop:

  1. 使用 addpoints 将新点添加到这些线。

  2. 关于 xy、yz、xz 平面的投影:
    点 (x0,y0,z0) 到由 z = -2 定义的 xy 平面的投影是 (x0,y0,-2)。因此,当你有一个点 (x,y,z) 时,你会以相同的方式投影到正确的平面。

  3. 对于连接当前点和投影的垂直线,在每次更新绘图时删除以前的点并重新绘制它们。这就是为什么我第一次打电话 clearpoints 删除任何先前的点,然后 addpoints 为从投影到实际 (x,y,z) 点的直线添加 2 个点。

  4. 对于"marker-lines",再次clearpoints然后添加新点。

  5. 所有的线都加点后,调用 drawnow 在下一次循环迭代之前同时更新所有行(并使更新显示为同步)。