• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Line drawing algorithms

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does anyone know the algorithm for drawing polygonal lines (ie: from (x1,y1) to (x2,y2) for any value of the x/y variables)? I can't use the Java libraries to do it because, to be honest, I'm doing it in C and I haven't got enough program memory to store the maths libraries. I haven't been able to find any algortihms on the net and, while I'm close to figuring it out myself, I'm getting stuck on working out the gradient loops.

So far i've got this:

y = (int)y2 - (int)y1; // finds length of y
x = x2 - x1;// finds length of x
m = (y/x); // Grad of line
c = y-mx; // intersection w/ y-axis


if(x<0)
{
x = x*-1; // Make the length positive for use in loop
}

if(y<0)
{
y = y*-1; // Make the length positive for use in loop
}

if(y<x)
{
for(i=x1; i<=x2; i++)
{

}
}
else
{
for(i=y1; i<=y2; i++)
{

}
}

and a load of ideas in my head that dont work s

Thanks in advance.
 
Get meta with me! What pursues us is our own obsessions! But not this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic