Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Help-Draw a star

0 views
Skip to first unread message

Neo

unread,
Feb 19, 2008, 4:56:22 AM2/19/08
to
I need to draw a rasterisation of a star using a DDA
algorithm. I'm told this is really simple, I am almost there
I have managed to program half of the star but cant work
out how to program the other half.

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

Walter Roberson

unread,
Feb 19, 2008, 10:41:52 AM2/19/08
to
In article <fpe946$t0e$1...@fred.mathworks.com>,

Neo <will...@hotmail.com> wrote:
> I need to draw a rasterisation of a star using a DDA
>algorithm.


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

0 new messages