2017-02-14 8 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

こんにちは、私はあなたのコードの一般的な意味を取得しますが、一部はかなり曖昧です。それらを簡単にpls説明できますか?なぜx1、y1の行列を10回複製する必要がありますか?プラス、ユークリッド距離の差分累積和はどのように周縁を与えるのですか?そこに行方不明の定理はありますか?ありがとうございました。 – Vino

+0

こんにちは、単調でないデータを補間することはできません。したがって、5点で作成されたポリゴンの長さに対応する 't'ベクトルを使用して補間を単調にする必要があります。私の答えの最初の図を見て、細い線は、x1とy1が複製されなかった場合の補間形状を表します。しかし、x1ベクトルとy1ベクトルを複製すると、補間は規則的な形状(太い線)に向かって収束する傾向があります – obchardon

関連する問題