

using MATLAB to visualize field of view coding question.
I am attempting to the field of view of a robot with 360 degree vision within MATLAB. Basically I want to place the robot somewhere randomly on a 2d with obstacles and show the area in which the obstacles are not blocking the robot's vision.
I have some code but it's not working correctly and Im unsure how to go about fixing it. The basic idea is that the code goes through every point and finds the linear equation that joins those two points. If an obstacles lies on that point it does not that line. My problem is that the search for an obstacles does not originate at the robot but at the origin instead which gives me bad results. I am not a programmer and don't really know how to go about fixing this. Any help would be greatly appreciated! Thx. Code:
clc close all clear all img = imread('workspace.png')>1; for i = 1:size(img,1) for j = 1:size(img,2) if img(i,j) == 0 img(i,j) = 1; else img(i,j) = 0; end end end imagesc(img) hold on x_axis = 1:1:size(img,2); good = 1; yrz = []; xz = []; [startx,starty] = ginput(1); startx = round(startx); starty = round(starty); ymax = size(img,1); xmax = size(img,2); for ii = 1:ymax %%y for jj = 1:xmax %%x if jj == startx y = 1:1:ymax; x = ones(1,xmax)*jj; yr = round(real(y)); ind = find(yr <= ymax & yr > 0); y = y(ind); yr = yr(ind); x = x(ind); else y = ((iistarty)/(jjstartx))*(x_axisstartx)+starty; yr = round(real(y)); ind = find(yr <= ymax & yr > 0); y = y(ind); yr = yr(ind); x = x_axis(ind); end for kk = 1:size(ind,2); if img(yr(kk),x(kk)) ==1 && good == 1 yrz = y(1:kk1); xz = x(1:kk1); % yrz = [yrz,yr(k)]; % xz = [xz,x(k)]; good = 0; end end plot(xz,yrz,'ro') %plot(x,yr,'bs') good = 1; yrz = []; xz = []; end end plot(startx,starty,'gd') %axis([1 size(img,2) 1 size(img,1)]) hold off This picture is the environment I am working with. It's basically a .png with white as free space and black as obstacles. This is just an example of an environment space and I would like it to work with any shaped environment.
__________________
THA BREW HA HA PWNES J00! 
02242009, 06:01 PM 
#1

Advertisement  [Remove Advertisement] 


Just found out that I have been searching for the wrong terms in google. The formal term for this sort of thing is "visibility graphs." Using the right search term I found some algorithms I'm going to try out.
__________________
THA BREW HA HA PWNES J00! 
02252009, 07:57 AM 
#2

Thread Tools  

