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
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com