実行結果の直線を曲線にしたい
古いコメントを表示
sspファイルを用いて行っています 現段階で点を直線で結び「み」と表示されるようになっています。 点を結んだ際の直線を曲線にするにはどうしたらよいでしょうか。
function df_editor
% オブジェクトをマウスで動かすサンプル例
% Figure に各種コールバックを設定
figure('WindowButtonDownFcn',@myBDCallback,'WindowButtonUpFcn',@myBUCallback)
%pos=[50 50; 60 60; 70 70];
%axis([0,100,0,100]); axis square; hold on;
%xlabel('x'), ylabel('y');
%sspファイルの読み込み
po=sspread('mi.ssp');
pos(:,1)=po(:,1);
pos(:,2)=po(:,2);
%-200から200までの座標表示
axis([-200,200,-200,200]); axis square; hold on;
xlabel('x'), ylabel('y');
%img = imread('circle.png'); % 面を表示
for i=1:length(pos)-1
hL(i)=plot(pos(i:i+1,1),pos(i:i+1,2),'k-');
end
for i=1:length(pos)
h(i)=plot(pos(i,1),pos(i,2),'bx');
end
function myBDCallback(src,eventdata)
% WindowButtonDownFcn
% マウスを押したときのコールバック関数
set(src,'WindowButtonMotionFcn',@myBMCallback);
function myBMCallback(src,evnt)
% WindowButtonMotionFcn
% マウスを動かしたときのコールバック関数
Cp = get(gca,'CurrentPoint'); % 座標軸上のマウスの位置を取得
Xf = Cp(1,1); % X 軸上の位置
Yf = Cp(1,2); % Y 軸上の位置
[dp,Ip] = min((pos(:,1)-Xf).^2+(pos(:,2)-Yf).^2) %debug用にコメントアウト
set(h(Ip),'XData',Xf) % ボタンのX軸位置を変更
set(h(Ip),'YData',Yf) % ボタンのY軸位置を変更
if Ip==1
set(hL(Ip),'XData',[Xf,pos(Ip+1,1)]) % ボタンのX軸位置を変更
set(hL(Ip),'YData',[Yf,pos(Ip+1,2)]) % ボタンのY軸位置を変更
pos(Ip,:)=[Xf Yf];
elseif Ip==length(pos)
set(hL(Ip-1),'XData',[pos(Ip-1,1),Xf]) % ボタンのX軸位置を変更
set(hL(Ip-1),'YData',[pos(Ip-1,2),Yf]) % ボタンのY軸位置を変更
pos(Ip,:)=[Xf Yf];
else
set(hL(Ip),'XData',[Xf,pos(Ip+1,1)]) % ボタンのX軸位置を変更
set(hL(Ip),'YData',[Yf,pos(Ip+1,2)]) % ボタンのY軸位置を変更
set(hL(Ip-1),'XData',[pos(Ip-1,1),Xf]) % ボタンのX軸位置を変更
set(hL(Ip-1),'YData',[pos(Ip-1,2),Yf]) % ボタンのY軸位置を変更
pos(Ip,:)=[Xf Yf];
end
drawnow % 強制描画
end
end
function myBUCallback(src,evantdata)
% WindowButtonUpFcn
% マウスを放したときのコールバック関数
set(src,'WindowButtonMotionFcn','');
end
end
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Language Fundamentals についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

