i have two concentric circles and a set of random nodes generated inside both the circles, How to index these nodes which lie inside the smaller circle and which lie between the two circles

5 ビュー (過去 30 日間)
after indexing i want to find the distance of every nodefrom the center of the two circles

回答 (1 件)

Image Analyst
Image Analyst 2015 年 10 月 27 日
Try this:
clc; % Clear the command window.
clear all;
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
x0=3; % Center of the circle in the x direction.
y0=2; % Center of the circle in the y direction.
r=1;
r1=0.65;
teta=-pi:0.01:pi;
x=r*cos(teta)+x0;
y=r*sin(teta)+y0
x1=r1*cos(teta)+x0
y1=r1*sin(teta)+y0
plot(x,y,x1,y1)
hold on
scatter(x0,y0,'or')
axis square
%----------------------------------------
% divide your circle to n sectors
n=8
tet=linspace(-pi,pi,n+1)
xi=r*cos(tet)+x0
yi=r*sin(tet)+y0;
for k=1:numel(xi)
plot([x0 xi(k)],[y0 yi(k)], 'r*', 'MarkerSize', 10, 'LineWidth', 2)
hold on
end
% distribution of nodes
n=30;
angle1 = 0;
angle2 = 2*pi;
t = (angle2 - angle1) * rand(n,1) + angle1;
R = r*sqrt(rand(n,1));
xr = x0 + R.*cos(t);
yr = y0 + R.*sin(t);
% Now display our random set of nodes in a figure.
scatter(xr,yr,'g','MarkerFaceColor','c')
axis square;
grid on;
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
fontSize = 30;
xlabel('X', 'FontSize', fontSize);
ylabel('Y', 'FontSize', fontSize);
title('Random Locations Within a Circle', 'FontSize', fontSize)
% Find out which (xr, yr) are in between the circles.
radii = sqrt((xr-x0).^2 + (yr-y0).^2);
inBetween = radii > r1;
plot(xr(inBetween), yr(inBetween), 'bo', 'MarkerSize', 15);
  1 件のコメント
Image Analyst
Image Analyst 2015 年 10 月 27 日
To also get those points within a sector, just calculate the angles and use the same kind of logic:
clc; % Clear the command window.
clear all;
close all;
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
x0=3; % Center of the circle in the x direction.
y0=2; % Center of the circle in the y direction.
r=1;
r1=0.65;
teta=-pi:0.01:pi;
x=r*cos(teta)+x0;
y=r*sin(teta)+y0
x1=r1*cos(teta)+x0
y1=r1*sin(teta)+y0
plot(x,y,x1,y1)
hold on
scatter(x0,y0,'or')
axis square
%----------------------------------------
% divide your circle to n sectors
numberOfPoints=8
tet=linspace(-pi,pi,numberOfPoints+1)
xi=r*cos(tet)+x0
yi=r*sin(tet)+y0;
for k=1:numel(xi)
plot([x0 xi(k)],[y0 yi(k)], 'r*', 'MarkerSize', 10, 'LineWidth', 2)
hold on
end
% distribution of nodes
numberOfPoints = 150;
angle1 = 0;
angle2 = 2*pi;
t = (angle2 - angle1) * rand(numberOfPoints,1) + angle1;
R = r*sqrt(rand(numberOfPoints,1));
xr = x0 + R.*cos(t);
yr = y0 + R.*sin(t);
% Now display our random set of nodes in a figure.
scatter(xr,yr,'g','MarkerFaceColor','c')
axis square;
grid on;
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
fontSize = 30;
xlabel('X', 'FontSize', fontSize);
ylabel('Y', 'FontSize', fontSize);
title('Random Locations Within a Circle', 'FontSize', fontSize)
% Find out which (xr, yr) are in between the circles.
radii = sqrt((xr-x0).^2 + (yr-y0).^2);
inBetween = radii > r1;
plot(xr(inBetween), yr(inBetween), 'bo', 'MarkerSize', 15);
% Find angles of all points from the center of the circles.
angles = atan2((yr-y0),(xr-x0))
% Plot a blue diamond over angles between 3*pi/4 and pi/2
% First find indexes of those points in that angle sector.
selectedAngles = angles > 2*pi/4 & angles < 3*pi/4;
% Also make sure it's in the "in between" annular region
selectedAngles = selectedAngles & inBetween;
plot(xr(selectedAngles), yr(selectedAngles), 'bd', 'MarkerSize', 25, 'LineWidth', 2);
See the points outlined in a blue diamond in the upper left of the figure below:

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by