1
我正在尋找一種方法來隔離圓內圓的x和/或y座標,如圖中所示。Matlab - 隔離圓內圓的x/y值
我需要隔離這個這樣我就可以設定的條件是,當球進入圓形,我可以改變球的一些性質,我已經能夠用於外圓,做到這一點,其使用下面的代碼集中在[0 0],
while sqrt(XY(1)^2 + XY(2)^2) < 5
但無法弄清楚如何爲內部圓做它。
感謝
我正在尋找一種方法來隔離圓內圓的x和/或y座標,如圖中所示。Matlab - 隔離圓內圓的x/y值
我需要隔離這個這樣我就可以設定的條件是,當球進入圓形,我可以改變球的一些性質,我已經能夠用於外圓,做到這一點,其使用下面的代碼集中在[0 0],
while sqrt(XY(1)^2 + XY(2)^2) < 5
但無法弄清楚如何爲內部圓做它。
感謝
如果你知道中心和內圓你能夠計算圓的X
和Y
座標然後半徑,可以使用inpolygon功能thest點是否內圓(inpolygon
返回1
如果一個點在多邊形內,否則0
)。在這種情況下,多邊形由圓的點構成。
在下面的代碼中,一個點跨三個圓圈(其中兩個放置在較大的圓圈內)。
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
希望這有助於。
Qapla'
你對內圈有什麼瞭解?中心?半徑? –
它有助於其他用戶,並習慣於在問題中收到您[收到的答案(鏈接)](http://stackoverflow.com/help/someone-answers)。 – zdim