Below is my 2 M-files so far...I'm told the first one is
100% correct but I have slight errors in the second.
1) Star.m
screen=ones(110,110);
coord=[40 70; 5 55; 40 40; 55 5; 70 40; 105 55; 70 70; 55 105];
for i=1:7
first=coord(i,:);
last=coord(i+1,:);
screen=dda(screen,first,last,0);
end
clf
imagesc(flipud(screen'));
title('..');
xlabel('..');
ylabel('..');
axis square;
colormap(gray);
2) DDA.m
function raster=dda(raster,first,last,color)
%check whether line is drawn from left to right
if(last(1)<first(1))
temp=last;
last=first;
first=temp;
end
%calculate the gradient
grad=(last(2)-first(2))/(last(1)-first(1));
x=first(1);
y=first(2);
if (abs(grad)<1)
for x=first(1):last(1)
raster(x,round(y))=color;
y=y+grad;
end
elseif (abs(grad)>1)
for y=first(2):last(2)
raster(y,round(x))=color;
x=x+1/grad;
end
end
Any help is much appreciated,
Neo
Posting the same question three times in two days doesn't
help people think any faster. For example, using the same
phrasing each time hasn't helped me figure out what a
"DDA algorithm" is.
--
"When a scientist is ahead of his times, it is often through
misunderstanding of current, rather than intuition of future truth.
In science there is never any error so gross that it won't one day,
from some perspective, appear prophetic." -- Jean Rostand