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