Speed ​​up staining segments of a spline curve?

I am trying to highlight segments of a spline curve with different RGB values. Thanks a lot @Suever, I have a working version:

x = [0.16;0.15;0.25;0.48;0.67]; y = [0.77;0.55;0.39;0.22;0.21]; spcv = cscvn([x, y].'); % spline curve N = size(x, 1); figure; hold on; for idx = 1:N-2 before = get(gca, 'children'); % before plotting this segment fnplt(spcv, spcv.breaks([idx, idx+1]), 2); after = get(gca, 'children'); % after plotting this segment new = setdiff(after, before); set(new, 'Color', [idx/N, 1-idx/N, 0, idx/N]); % set new segment to a specific RGBA color end hold off; 

Now I want to speed it up. Is it possible?

+5
source share
1 answer

There are no explicit benchmarks per se, but you can easily do this as well. collect the collected points and divide them into "segments" (for example, using the buffer function)
b. setting the 'color' property for children (thanks to @Suever for indicating this can be done by an array of object descriptors directly )

 %% Get spline curve x = [0.16; 0.15; 0.25; 0.48; 0.67]; y = [0.77; 0.55; 0.39; 0.22; 0.21]; spcv = cscvn ([x, y].'); %% Split into segments pts = fnplt (spcv); xpts = pts(1,:).'; ypts = pts(2,:).'; idx = buffer ([1 : length(xpts)]', 10, 1, 'nodelay'); % 10pt segments lastidx=idx(:,end); lastidx(lastidx==0)=[]; idx(:,end)=[]; % correct last segment % Plot segments plot (xpts(idx), ypts(idx), xpts(lastidx), ypts(lastidx), 'linewidth', 10); % Adjust colour and transparency Children = flipud (get (gca, 'children')); Colours = hsv (size (Children, 1)); % generate from colourmap Alphas = linspace (0, 1, length (Children)).'; % for example set (Children, {'color'}, num2cell([Colours, Alphas],2)); 

enter image description here

Note. As also indicated in the comments section ( thanks to @ Dev-iL ), setting the color to the RGBA square as you ask (i.e. unlike a simple RGB triple) is newer (also currently undocumented ). Matlab function. This code, for example. will not work in 2013.

+4
source

Source: https://habr.com/ru/post/1258649/


All Articles