How can I display a line in 3D with a colour gradient?
6 次查看(过去 30 天)
显示 更早的评论
Let’s say I have a set of 10 tridimensional points, represented as a 3 by 10 matrix, such as these points generated just for the sake of illustration:
n = 10;
x = linspace(1, 2, n);
y = cos(x);
z = y.^2;
points = [x' y' z']
I can display them as a line in 3D:
plot3(points(:,1,:), points(:,2,:), points(:,3,:));
My question is: how can I apply a color gradient to this line, so we can see in what direction does the line evolve (relative to the order of the point in the points matrix)?
I tried several methods, without success so far:
- Calling plot3 with the c parameter (as suggested by an answer on the Internet): the c keyword is not recognised.
- Calling colormap with a custom made map: no graph is displayed at all, even though no error is thrown.
cmap = [linspace(0, 1, n)' zeros(n, 1) zeros(n, 1)];
colormap(cmap);
0 个评论
采纳的回答
Voss
2024-5-10
n = 10;
x = linspace(1, 2, n);
y = cos(x);
z = y.^2;
points = [x' y' z']
surf(points(:,[1 1]),points(:,[2 2]),points(:,[3 3]),[1:n; 1:n].', ...
'FaceColor','none','EdgeColor','interp','LineWidth',2)
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Orange 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!