how to find coordinates of a point at where 4 grids meets each other

2 ビュー (過去 30 日間)
kiranpreet kaur
kiranpreet kaur 2016 年 8 月 23 日
回答済み: KSSV 2016 年 8 月 26 日
a region is divided into 4 grids code is needed to find the coordinates of point at where grids met

回答 (3 件)

KSSV
KSSV 2016 年 8 月 23 日
編集済み: KSSV 2016 年 8 月 23 日
You have to give lot of information on this... How the grid data is? How the grids are? Do you have each grid separately? If you have each grid data separately, then you can use intersection of the data to get the common data.
  5 件のコメント
kiranpreet kaur
kiranpreet kaur 2016 年 8 月 23 日
close all; clc; ngrid=4; N=50; R=0.2; sink.x=3.1; sink.y=3.1; x = linspace(0, 4, ngrid+1); E=0.5; [X,Y] = meshgrid(x); figure(1) plot(X,Y,'k') hold on plot(Y,X,'k') hold on ngrid = 4; coords = rand(N,2) * ngrid; nodes = struct('x',coords(:,1),... %# Assign x coordinates 'y',coords(:,2),... %# Assign y coordinates 'energy',E);
scatter(coords(:,1),coords(:,2)); set(gca, 'XTick', 1:ngrid+1, 'YTick', 1:ngrid+1) axis square plot(nodes.x,nodes.y,'o','LineWidth',2, 'MarkerEdgeColor','b','MarkerFaceColor','b','MarkerSize',3) plot(sink.x,sink.y,'d','LineWidth',2, 'MarkerEdgeColor','r','MarkerFaceColor','y','MarkerSize',12)
KSSV
KSSV 2016 年 8 月 23 日
You better attach the .m file....

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


KSSV
KSSV 2016 年 8 月 23 日
This is the image I got...You want to find the black circles plotted on the image? If so, they already available in [X,Y].
If not, point what intersection point you want in the figure.
  2 件のコメント
kiranpreet kaur
kiranpreet kaur 2016 年 8 月 23 日
can u plz help me with some code
KSSV
KSSV 2016 年 8 月 25 日
Yes please.....!

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


KSSV
KSSV 2016 年 8 月 26 日
close all;
clc;
ngrid=4;%no. of grids
N=200;
R=0.5;
sink.x=3.1;
sink.y=3.1;
x = linspace(0, 4, ngrid+1);
E=0.5;
[X,Y] = meshgrid(x);
figure(1)
plot(X,Y,'k')
hold on
plot(Y,X,'k')
hold on
ngrid = 4;
coords = rand(N,2) * ngrid;
nodes = struct('x',coords(:,1),... %# Assign x coordinates
'y',coords(:,2),... %# Assign y coordinates
'energy',E);
scatter(coords(:,1),coords(:,2));
set(gca, 'XTick', 1:ngrid+1, 'YTick', 1:ngrid+1)
axis square
plot(nodes.x,nodes.y,'o','LineWidth',2, 'MarkerEdgeColor','m','MarkerFaceColor','m','MarkerSize',3)
plot(sink.x,sink.y,'d','LineWidth',2, 'MarkerEdgeColor','r','MarkerFaceColor','y','MarkerSize',12)
grid on;
%%Get nodes inside for each box
P1 = cell(4,4) ;
for i = 1:4
for j = 1:4
A = [X(i,j) Y(i,j)] ;
B = [X(i+1,j+1) Y(i+1,j+1)] ;
idx = find(nodes.x >= A(1) & nodes.x <B(1)) ;
idy = find(nodes.y >= A(2) & nodes.y <B(2)) ;
id = intersect(idx,idy) ;
P1{i,j} = [nodes.x(id) nodes.y(id)] ;
% plot points inside first box
plot(P1{i,j}(:,1),P1{i,j}(:,2),'*g')
end
end

カテゴリ

Help Center および File ExchangeWSNs についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by