I want move a Vertical line segment across a plane or another way sweep the plane, from Left to right.
The figure illustrates how the segment is moving at the X-axis. When x1 >= X beginning and i translate it to the upper part and so on, till y2 which is the upper part of the segment reaches Y. You can think of it as how a scanner works.
Line = (x1,y1,x2,y2)
When x1 pr x2 coordinates becomes greater or equal to -rightBorder I increase y1 and y2 to the next level and so on till y2 becomes greater than Y.
Algorithm:
#define STEP 9
#define Y 20
#define X 30
void moveLine(int, int, int, int);
int main()
{
moveLine(5, 0, 5, 10);
return 0;
}
void moveLine(int x1, int y1, int x2, int y2)
{
//Reaches upper border (Y-axis)
if (y1 >= Y)
{
return;
}
// cout << y1 <<" "<< y2 << endl;
// Increase y1 and y2 and Return to the beginning
if (x1 >= X)
{
//startint points
y1 += 10;
y2 += 10;
// Reinitialize x1 and x2
x1 = -4;
x2 = -4;
}
// sweep again
moveLine(x1 + STEP, y1, x2 + STEP,y2);
}
Explanation:
I start with x1 = 5, and x2 = 5, y1 = 5 and y2 = 10 then x1+=9, x2+=9 till x1 >= X, then I reinitialize the x1 and x2, and increase y1 by 5 and y2 + 5 till y2 becomes greater than Y.
I wrote the piece of Code. it worked ok, but I wanted to your advice and if the recursion function is okay.
Thank you.