2017-02-14 61 views

回答

3

通过使用样条插值可以达到类似的结果。在这个例子中,我复制了x1和y1向量的值,以避免在插值形状上产生不连续性。不幸的是,Octave的fill函数无法处理透明度,因此您可以自由地修改此代码以添加此选项。

n = 1000;          % # of interpolation points. 
p = 5           % # of label 
lab = {'text1','text2','text3','text4','text5'} % label 

theta = linspace(0,2*pi-(2*pi)/p,p); % The angle 
thetal = [theta(1),theta(end:-1:2)]; % Theta for placement of labels 
rho = [0.65 0.8 0.7 0.9 1]   % The spider graph values 

[x1,y1] = pol2cart(theta,rho) 

x1 = repmat(x1,1,10); 
y1 = repmat(y1,1,10); 

正如你可以在下面,如果我不复制X1和Y1矢量我会得到一些不连续的图中看到,当我计算插值:

enter image description here

t = [0,cumsum(sqrt(diff(x1).^2+diff(y1).^2))]; %cumsum(euclidian distance) => t(end) = perimeter. 
ti = linspace(0,t(end),n); 
x = interp1(t,x1,ti,'spline'); 
y = interp1(t,y1,ti,'spline'); 

%We plot the interpolated shape 
fill(x(round(0.5*n):round(0.6*n)),y(round(0.5*n):round(0.6*n)),[0.2,0.2,0.2]) %you need to start to fill your interpolated shape at another point than the first and last point if you want to avoid a discontinuity. 

hold on 

%Then we plot a circle and some other stuff 
set(gca,'Color',[0.6 0.6 0.6]); 
%plot(0,0,'bo') 
plot(x1,y1,'o','Color',[0.4,0.4,0.4],'MarkerSize',3,'MarkerFaceColor','auto') 
plot(sin(0:0.1:2*pi+0.1),cos(0:0.1:2*pi+0.1),'Color',[0.4,0.4,0.4],'linewidth',3) 
for i = 1:p 
    plot([0,sin(theta(i)+pi/2)],[0,cos(theta(i)+pi/2)],'Color',[0.4,0.4,0.4],'linewidth',3); 
    h(i) = text(sin(theta(i)+pi/2),cos(theta(i)+pi/2),lab{i}); 
    set(h(i), 'rotation', rad2deg(thetal(i))-90,'HorizontalAlignment','center','VerticalAlignment','bottom') 
end 
ylim([-1.2,1.2]) 
xlim([-1.2,1.2]) 
axis equal 

结果

enter image description here

+0

非常感谢您花时间回答我的问题:) – Vino

+0

您好,我了解您的代码的一般意义,但有些部分非常模糊。你可以简单解释一下吗?为什么我们必须重复x1,y1矩阵10次?另外,欧差距离的累积和差是如何给你的周长?有没有我在那里失踪的定理?谢谢。 – Vino

+0

嗨,你不能插值非单调数据,所以我强制插值通过使用与您的5点创建的多边形的长度相对应的't'向量单调。看看我的答案中的第一个数字,如果x1和y1未被复制,细线代表插值形状。但是,如果我们复制x1和y1矢量,插值往往趋于规则形状(粗线) – obchardon