Thread: Help
View Single Post
Old 02-19-2005, 08:52 AM   #4 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
Oh come on. You can do DDA. Even I needed only 2 minutes of study. This is the result:
Code:
#include <iostream>

using namespace std;

void DDA(int x1,int y1,int x2, int y2)
{
  int length;
  double x,y;
  double xIncr, yIncr;

  length = abs(x2 - x1);
  if (abs(y2 - y1) > length)
  {
    length = abs(y2 - y1);
  }
  xIncr = (double)(x2 - x1)/(double)length;
  yIncr = (double)(y2 - y1)/(double)length;
  x = x1 + 0.5;
  y = y1 + 0.5;
  while(length)
  {
    cout<<(int)x<<", "<<(int)y<<endl;
    x += xIncr;
    y += yIncr;
    --length;
  }
}

int main(int argc, char *argv[])
{
  DDA(-5, -3, 5, 9);
  
  cin.get();
  return 0;
}
__________________
Valmont is offline   Reply With Quote