2D matrix viewshed
Show older comments
Hi everyone,
I have a binary matrix which represents the floorplan of a building, given a position in this floorplan I would like to know all of the positions visible by direct line of sight. At the moment I am implementing the viewshed function by passing by binary matrix as an elevation map, i.e.:
floorplan = padarray(false(150,150),[1 1],true,'both'); % 1s = walls, 0s = space
floorplan(75,1:75) = true;
Z = floorplan.*100;
R = georefcells([0 1],[0 1],size(floorplan));
ind = 3000;
[rx,cx] = ind2sub(size(floorplan),ind);
xnow = (rx-1)./(size(floorplan,1)-1);
ynow = (cx-1)./(size(floorplan,2)-1);
los = viewshed(Z,R,xnow,ynow,50,0,"AGL","AGL",1e2);
figure
subplot(1,2,1)
imshow(floorplan); hold on;
plot(cx,rx,'r+')
axis on xy
title('floorplan')
subplot(1,2,2)
imshow(los); hold on;
plot(cx,rx,'r+')
axis on xy
title('line of sight')
However, the viewshed function is a bit overpowered for this purpose because it is designed to work with 3D elevation data. To increase speed I was wondering if there is a faster way to achieve what I want? The documentation for viewshed doesn't specify how it works, so I'm not sure if I can simplify it for a 2D situation?
Thanks for any help.
Accepted Answer
More Answers (0)
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
