Thread Subject: DDA Algorithm of a Star

Subject: DDA Algorithm of a Star

From: Neo

Date: 18 Feb, 2008 20:13:02

Message: 1 of 1

Hi, I'm new to Matlab and am in need of a little help. I
currently study a University module which involves a lot of
matlab.

My task is 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.

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
straight Neo 18 Feb, 2008 15:14:56
line Neo 18 Feb, 2008 15:14:56
draw Neo 18 Feb, 2008 15:14:56
rasterization Neo 18 Feb, 2008 15:14:54
raster Neo 18 Feb, 2008 15:14:54
algorithm Neo 18 Feb, 2008 15:14:54
star Neo 18 Feb, 2008 15:14:54
dda Neo 18 Feb, 2008 15:14:54
rssFeed for this Thread

Contact us at files@mathworks.com