<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/164024</link>
    <title>MATLAB Central Newsreader - DDA Algorithm of a Star</title>
    <description>Feed for thread: DDA Algorithm of a Star</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Mon, 18 Feb 2008 20:13:02 -0500</pubDate>
      <title>DDA Algorithm of a Star</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/164024#415860</link>
      <author>Neo </author>
      <description>Hi, I'm new to Matlab and am in need of a little help. I&lt;br&gt;
currently study a University module which involves a lot of&lt;br&gt;
matlab. &lt;br&gt;
&lt;br&gt;
My task is to draw a rasterisation of a star using a DDA&lt;br&gt;
algorithm. I'm told this is really simple, I am almost there&lt;br&gt;
I  have managed to program half of the star but cant work&lt;br&gt;
out how to program the other half. &lt;br&gt;
&lt;br&gt;
Below is my 2 M-files so far...I'm told the first one is&lt;br&gt;
100% correct but I have slight errors in the second. &lt;br&gt;
&lt;br&gt;
1) Star.m&lt;br&gt;
&lt;br&gt;
screen=ones(110,110);&lt;br&gt;
&lt;br&gt;
coord=[40 70; 5 55; 40 40; 55 5; 70 40; 105 55; 70 70; 55 105];&lt;br&gt;
for i=1:7&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;first=coord(i,:);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;last=coord(i+1,:);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;screen=dda(screen,first,last,0);&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
clf&lt;br&gt;
imagesc(flipud(screen'));&lt;br&gt;
title('..');&lt;br&gt;
xlabel('..');&lt;br&gt;
ylabel('..');&lt;br&gt;
axis square;&lt;br&gt;
colormap(gray);&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
2) DDA.m&lt;br&gt;
&lt;br&gt;
function raster=dda(raster,first,last,color)&lt;br&gt;
&lt;br&gt;
%check whether line is drawn from left to right&lt;br&gt;
if(last(1)&amp;lt;first(1))&lt;br&gt;
temp=last;&lt;br&gt;
last=first;&lt;br&gt;
first=temp;&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
%calculate the gradient&lt;br&gt;
grad=(last(2)-first(2))/(last(1)-first(1));&lt;br&gt;
&lt;br&gt;
x=first(1);&lt;br&gt;
y=first(2);&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
if (abs(grad)&amp;lt;1)&lt;br&gt;
for x=first(1):last(1)&lt;br&gt;
raster(x,round(y))=color;&lt;br&gt;
y=y+grad;&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&lt;br&gt;
elseif (abs(grad)&amp;gt;1)&lt;br&gt;
for y=first(2):last(2)&lt;br&gt;
raster(y,round(x))=color;&lt;br&gt;
x=x+1/grad;&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
end&lt;br&gt;
&amp;nbsp;&lt;br&gt;
&lt;br&gt;
Any help is much appreciated,&lt;br&gt;
&lt;br&gt;
Neo.</description>
    </item>
  </channel>
</rss>

