Created
January 2, 2013 10:36
-
-
Save 0xKD/4433678 to your computer and use it in GitHub Desktop.
DDA in C++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#define ROUND(a) ((int)(a + 0.5)) | |
using namespace std; | |
int drawDDA(int x1,int y1,int x2,int y2) | |
{ | |
float x = x1, y = y1; | |
int len = (x2-x1)>(y2-y1)?(x2-x1):(y2-y1); | |
float dx = (x2-x1)/(float)len; | |
float dy = (y2-y1)/(float)len; | |
cout<<"x = "<<ROUND(x)<<", y = "<<ROUND(y)<<"\n"; | |
for (int k=0; k < len; k++) | |
{ | |
x += dx; | |
y += dy; | |
cout<<"x = "<<ROUND(x)<<", y = "<<ROUND(y)<<"\n"; | |
} | |
return 0; | |
} | |
int main() | |
{ | |
drawDDA(2,5,10,20); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment