I have an exam in graphics informatic and I am trying to understand the Bresenham algorithm. I understand displaying a line and a circle (I think) but when I do an exercise where I have to display a hyperbolic function I can't make it right.
The hyperbolic function has the equation y = 100/x and I converted it to x*y - 100 = 0. I assume that the currently displayed pixel is at (x_p, y_p) on the screen. I calculated the increments and I found I = 2y_p - 1 when the pixel to be displayed is the one at the right, and I = 2y_p - 2x_p - 5 when the pixel to be displayed is at the bottom right. But now I don't know how to initialise. In my courses, the initialisation for a line is made at x_0 = 0, y_0 = 0, for a circle of a radius R, it is x_0 = 0, y_0 = R, but what is it for my hyperbole ?
I want to trace the hyperbole from x = 10 up to x = 20
void trace (const int x1, const int y1, const int x2)
{
int x = x1;
int y = y1;
int FM = //what to put here ???
glVertex2i(x,y);
while (x < x2)
{
if (FM < 0)
{
++x; --y;
const int dSE = 2*y - 2*x - 5;
FM += dSE;
}
else
{
++x;
const int dE = 2*y - 1;
FM += dE;
}
glVertex2i(x,y);
}
}
so I called this function like that :
glBegin(GL_POINTS);
trace(10,10,20);
glEnd();
I know it is old OpenGL, I use it just for testing purposes.