# How to map subdivisions in a squared geometry

3 views (last 30 days)

Show older comments

I have a geometry of a square with 4 edges. Each edge has 5 points and 4 cells (subdivisons). The image bellow illustrates it.

If I have a line going from, say cell(1), Ind(1), Edge(1), I want to define all its possible intersections with the rest of the cells in the remaining 3 edges. So, for example, a line going from cell(1), Ind(1), Edge(1), can intersect with cells of indices 5, 6, 7 ,...., 16. And then, do the same for the next cell. And so on so forth. Each cell has three possible edges to intersect with one of their cells.

This is my attempt of the code.

%set up the vertices' coordinates of the polygon (square in our case)

sx = [0 1 1 0];

sy = [0 0 1 1];

%Define the number of vertices

NVert = length(sx);

%go through the sides and compute their lengths

for j = 1:NVert %side

jp = j+1; %next side

if (jp > NVert)

jp = jp - NVert;

end

%compute the edge lengths (unit length)

SL(j) = sqrt((sx(j)-sx(jp))^2+(sy(j)-sy(jp))^2);

%number of points on each side/edge

nPoint(j) = round(SL(j)/ds);

%cumalative number of points

cPoint(j) = sum(nPoint(1:j));

%number of subdivisions/pixels/blocks/cells

nSubDiv(j) = nPoint(j) - 1;

%cumalative number of subdivisions/pixels/blocks/cells

cSubDiv(j) = sum(nSubDiv(1:j));

end

for j = 1:NVert %a loop over all the edges/vertices

for i = 1:nPoint(j) %a loop over the number of points each edge

%points index

pInd(i,j) = nPoint(1)*(j-1)+i;

end

for k = 1:nSubDiv(j)

%subdivisions index

sInd(k,j) = nSubDiv(1)*(j-1)+k;

end

end

%reshape the point index matrix into a vector

pInd = reshape(pInd(:,:),ns,1);

%reshape the cell index matrix into a vector

sInd = reshape(sInd(:,:),nSubDiv(1)*nSubDiv(1),1);

%edges mappings (here where I need help.)

for j = 1:NVert %a loop over all the edges/vertices

for i = 1:nSubDiv(j) %a loop over the number of subdivisions each edge

%Each cell has three possible edges to intersect with one of their cells.

end

end

Any help would be appreicted.

Thanks.

##### 0 Comments

### Answers (2)

KSSV
on 19 Jul 2021

x = 1:5 ;

y = 1:5 ;

[X,Y] = meshgrid(x,y) ;

X(3,3) = NaN ; Y(3,3) = NaN ;

plot(X,Y,'r',X',Y','r')

Matt J
on 19 Jul 2021

##### 0 Comments

### See Also

### Categories

### Community Treasure Hunt

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

Start Hunting!