2016-03-28 11 views
1

画像に示すように、円内の円のx座標とy座標を分離する方法を探しています。私は、私は外側の円のためにこれを行うことができたので、私はボールが円に入ったとき、私はボールのいくつかの性質を変えることができるという条件を設定することができ、これを分離する必要がMatlab - 円内の円のx/y値を隔離する

enter image description here

while sqrt(XY(1)^2 + XY(2)^2) < 5 

[0 0]の中央に配置されていますが、内側の円の作成方法はわかりません。

おかげ

+0

内側の円については何を知っていますか?センター?半径は? –

+0

これは、他のユーザーに役立ちますが、慣習的ですが、あなたは質問で受け取った[回答(リンク)をマークする](http://stackoverflow.com/help/someone-answers)です。 – zdim

答えて

3

あなたが中心とあなたが円のXY座標を計算することができ、内側の円の半径がわかっている場合はポイントが内部にある場合は、thestにinpolygon関数を使用することができ円(inpolygonは、ポイントがポリゴンの内側にある場合は1、それ以外の場合は0を返します)。この場合、ポリゴンは円の点によって構成されます。

次のコードでは、点は3つの円(2つの円はより大きなものの内側に配置されています)を移動します。

inpolygon機能は、ポイント(ボール)が円の内側にあり、内側にある円に従って色が変化するかどうかをテストするために使用されます。

% Define the radius and centre of three circles 
r1=10; 
r2=3 
r3=4 
c1=[0 0]; 
c2=[3 3]; 
c3=[-4 -4] 
% Calculate the X and Y coord of the three circles 
t=0:.01:2*pi; 
x=cos(t)*r1 
y=sin(t)*r1 
x1=cos(t)*r2+c2(1) 
y1=sin(t)*r2+c2(2) 
x2=cos(t)*r3+c3(1) 
y2=sin(t)*r3+c3(2) 
% Plot the circles 
plot(x,y,'r') 
hold on 
plot(x1,y1,'g') 
plot(x2,y2,'b') 
daspect([1 1 1]) 
% Define the ball trajectory 
mx=-10:1:10; 
my=-10:1:10; 
for i=1:length(mx) 
    % Plot the ball: black if outside of all the circle 
    mh=plot(mx(i),my(i),'o','markerfacecolor','k','markeredgecolor','k') 
    % If the ballk is inside the first circle, make it red 
    if(inpolygon(mx(i),my(i),x,y)) 
     mh.MarkerFaceColor='r'; 
     mh.MarkerEdgeColor='r'; 
    end 
    if(inpolygon(mx(i),my(i),x1,y1)) 
    % If the ballk is inside the second circle, make it green 
     mh.MarkerFaceColor='g'; 
     mh.MarkerEdgeColor='g'; 
    end 
    if(inpolygon(mx(i),my(i),x2,y2)) 
    % If the ballk is inside the third circle, make it blue 
     mh.MarkerFaceColor='b'; 
     mh.MarkerEdgeColor='b'; 
    end 
    pause(1) 
end 

enter image description here

この情報がお役に立てば幸いです。

カプラ '