이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
Make grid from patch object
조회 수: 5 (최근 30일)
이전 댓글 표시
proczell
2018년 1월 25일
Hi
I am trying to make a function for splitting a patch object into N equally sized indexed rectangles (like a grid). The intended use is that the patch object contains the (x,y) values for a floor in a room, and I want to split the room into N number of rectangles which later will be used to make a "Region of Interest" in an optimization problem.
Any help would be highly appreciated.
댓글 수: 12
Walter Roberson
2018년 1월 25일
So for example it needs to be able to divide up a room that looks like this:
-----
| |
________| |
| |
| ___|
| |
|________|
into
-----
| |
________| |
| + + |
| + +___|
| + |
|___+____|
for N = 3, declare failure for N = 4 or N =5, for N = 6 it could subdivide those horizontally or could instead divide into 2 x 2 squares? And for higher numbers with more irregular walls it might have to "jig-saw", using a mix of horizontal and vertical orientations to fit all of the edge conditions?
proczell
2018년 1월 25일
Yes, that is the general idea, although it should be noted that the room is not necesarilly make up op straight lines, it could look something like:
|\
| \
| \ /\
| \/ \
| |
| |
| |
|_______|
which may make it a bit more complicated. The thread you posted looks like is largely related to the same problems, although not in Matlab. Do you know any Matlab tools that may be helpful? If not I will certainely look through that thread and see if there may be anything helpful. Thanks!
My latest idea is in the lines of dividing the polygon with Delauney Triangulation and then try to divide the triangles into new cells again. But I don't know if it will be a good solution.
Thanks for your answer!
Walter Roberson
2018년 1월 25일
In order to be able to divide an area into rectangles that are not infinitely small, all internal angles must be multiples of 90 degrees -- unless, that is, it is permitted to have space left over, in which case ideally you would prefer to minimize the space left over.
proczell
2018년 1월 26일
That is true. Some space needs to be left over, but if the space is close to the "walls" it should be okay.
proczell
2018년 1월 26일
Do you know if Matlab includes any kind of "fishnet" function to divide polygons?
Walter Roberson
2018년 1월 26일
MATLAB itself does not have such a function.
I do not find such a function for MATLAB when I google, but perhaps different keywords would make a difference.
proczell
2018년 1월 26일
I have not found any functions, from Matlab, Python or any other language I am familiar with. May have to try and make the function myself as it is absolutely necessary for my task.. Thanks for your help!
Walter Roberson
2018년 1월 26일
With calls to arcgis: https://gis.stackexchange.com/questions/115351/automate-splitting-polygons-into-sections
proczell
2018년 1월 26일
Since you have shown interest in helping me, I though I would post the current code, which seems to have a good potential.
area = 45.020;
sq_area = area/50;
side = sqrt(sq_area);
ylim = 5;
xlim = 4;
i = 1;
origin = [0 ;0]
L = origin;
figure
bOK = true
while(bOK)
L = [origin(1) ;origin(2)+side];
B = [origin(1) + side ;origin(2)];
R = [origin(1) + side ;origin(2) + side];
if L(1) < xlim
if L(2) < ylim
cubes{i} = [origin B R L origin]
curr_cube = cubes{i}
hold on
plot(curr_cube(1,1:end),curr_cube(2,1:end),'b')
origin = [L(1) ;L(2)]
i = i + 1;
else
cubes{i} = [origin B R L origin]
curr_cube = cubes{i}
hold on
plot(curr_cube(1,1:end),curr_cube(2,1:end),'b')
origin = [B(1) ;0]
i = i + 1;
end
else
bOK = 0;
end
pause(0.5)
end
This will swipe along the y-axis, but could easily be extended to a possibility for swiping along the x-axis. The final problem to solve is to make xlim and ylim dynamic according to the given room, a problem I think is highly solvable.
proczell
2018년 1월 27일
Another update. This works as intended, but if anyone finds improvements or errors, please let me know.
clear all ;close all; clc
x = [0 18.01 18 14.51 0];
y = [0 0 0 0 0];
z = [0 0 5.0 2.5 24];
% Patch object
nlin = 200;
for i = 1:length(x)
if i == length(x)
if x(i) == x(1)
x_l(i,1:nlin) = x(i);
y_l(i,1:nlin) = linspace(z(i),z(1),nlin);
else
xd = x(i) + x(1); zd = z(i) + z(1);
m = (z(i) - z(1))/(x(i) - x(1));
x_l(i,1:nlin) = linspace(x(i),x(1),nlin);
y_l(i,1:nlin) = m*x_l(i,1:nlin) - m*x(i) + z(i);
end
else
xd = x(i) + x(i+1); zd = z(i) + z(i+1);
m = (z(i) - z(i+1))/(x(i) - x(i+1));
x_l(i,1:nlin) = linspace(x(i),x(i+1),nlin);
y_l(i,1:nlin) = m*x_l(i,1:nlin) - m*x(i) + z(i);
end
end
y_l = [y_l(1,1:end) y_l(2,1:end) y_l(3,1:end) y_l(4,1:end),y_l(5,1:end)];
x_l = [x_l(1,1:end) x_l(2,1:end) x_l(3,1:end) x_l(4,1:end) x_l(5,1:end)];
% hold on
figure
p = patch(x,y,z,'r')
figure
scatter(x_l,y_l)
% Compute area
verts = get(p, 'Vertices');
faces = get(p, 'Faces');
a = verts(faces(:, 2), :) - verts(faces(:, 1), :);
b = verts(faces(:, 3), :) - verts(faces(:, 1), :);
c = cross(a, b, 2);
area = 1/2 * sum(sqrt(sum(c.^2, 2)));
% Fishnet generation
area = 45.020;
sq_area = area/50;
side = sqrt(sq_area);
ylim = 5;
xlim = 4;
i = 1;
origin = [0 ;0]
L = origin;
x_2 = round(x_l,1);
xlim = max(x_l)
bOK = true
while(bOK)
L = [origin(1) ;origin(2)+side];
B = [origin(1) + side ;origin(2)];
R = [origin(1) + side ;origin(2) + side];
L_2 = round(R(1),1);
x_current = find(x_2==L_2)
for i = 1:length(x_current)
y_vals = y_l(x_current);
ylim = max(y_vals)
end
if L(1) < xlim
if L(2) < ylim
cubes{i} = [origin B R L origin];
curr_cube = cubes{i};
hold on
plot(curr_cube(1,1:end),curr_cube(2,1:end),'k')
origin = [L(1) ;L(2)]
i = i + 1;
else
cubes{i} = [origin B R L origin];
curr_cube = cubes{i};
hold on
plot(curr_cube(1,1:end),curr_cube(2,1:end),'k')
origin = [B(1) ;0]
i = i + 1;
end
else
bOK = 0;
end
pause(0.03)
end
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Polygons에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)
