How can I display a line in 3D with a colour gradient?
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Akzeptierte Antwort
Voss
am 10 Mai 2024
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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Red finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!