Matlab利用序列离散点绘制渐变颜色空间曲线

写论文时候,可能会用到绘制空间曲线。这里给出一个自己写的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

% the 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

 

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值