寫論文時候,可能會用到繪製空間曲線。這裏給出一個自己寫的matlab函數,用於將一組離散的3D點繪製成空間曲線。點多的時候效果比較好,因爲每兩個點之間是直線連接。曲線的顏色是從起點到終點漸變的~
function [ ] = DrawColorfulCurve( PointList, startPointColor,endPointColor,circleRadius)
%DRAWCOLORFULCURVE 繪製從起點到終點顏色漸變的空間曲線
%PointList :3D point array
%startPointColor: the color of starting point
%endPointColor: the color of end point
%circleRadius: the tadius of starting and end points
% Below is some default params
if(nargin<2)
startPointColor = [1,0,0];
endPointColor = [0,1,0];
circleRadius=50;
elseif(nargin<4)
circleRadius=50;
end
% tha main function body
[PointNUM, temp] = size(PointList);
colorStep = (endPointColor-startPointColor)/(PointNUM-1);
for i=1:PointNUM-1
plot3(PointList(i:i+1,1),PointList(i:i+1,2),PointList(i:i+1,3),'color',colorStep*(i-1)+startPointColor);
hold on
end
hold on
scatter3(PointList(1,1),PointList(1,2),PointList(1,3),circleRadius,startPointColor);
hold on
scatter3(PointList(PointNUM,1),PointList(PointNUM,2),PointList(PointNUM,3),circleRadius,endPointColor);
end
clear all
PointList =load('TrajectoryData.txt');
DrawColorfulCurve(PointList);
grid on
給出一個參考數據點文件,繪製效果如下圖。
鏈接: https://pan.baidu.com/s/1lPBEU5uvPUvqtClo2gbFvA 密碼: kd8x