Does anyone know that if there is a modified version of Bresehham's line algorithm that uses feedback control with PID filters? Basically, the algorithm is just a P-Feedback Control for the error term amplified by half. I looked at the Graphics Gems series, Abrash's book,..etc can't find any yet
Asked
Active
Viewed 119 times
0
-
Can you expand a bit on what this "PID filter" is or where to find more information on it? The `pid` in your tags does not seem to relate to its description. – Jongware Oct 20 '14 at 15:34
-
I doubt it. Bresenham solves a very specific error minimization problem for a "controlled entity" with trivial, perfectly understood response dynamics. PID controllers are for general control problems where the controlled entity has poorly understood response. – Gene Oct 20 '14 at 16:22
-
@Jongware that was a typo actually. – andre_lamothe Oct 20 '14 at 18:27
1 Answers
0
Here it is: From Here. This uses the P parameter (see steps in pseudo code shown at top of link)
The provided example code was written in an old environment (references to TurboC in code) and contains functions that will have to be written by you. eg. initgraph()
, putpixel()
, etc. But the algorithm appears to be complete.
#include <stdio.h>
#include <conio.h>
#include <graphics.h>
#include <math.h>
#include <dos.h>
int main() {
/* request auto detection */
int gdriver = DETECT, gmode;
int x1 = 0, y1 = 0, x2, y2;
int err, x, y, dx, dy, dp, xEnd;
int twody, twodxdy;
/* initialize graphic driver */
initgraph(&gdriver, &gmode, "C:/TURBOC3/BGI");
err = graphresult();
if (err != grOk) {
/* error occurred */
printf("Graphics Error: %s\n",
grapherrormsg(err));
return 0;
}
/* max position in x and y axis */
x2 = getmaxx();
y2 = getmaxy();
/* draws line from (0, 0) to (x2, y2) */
dx = x2 - x1;
dy = y2 - y1;
twody = 2 * dy;
twodxdy = 2 * (dy - dx);
dp = twody - dx;
if (x1 > x2) {
x = x2;
y = y2;
xEnd = x1;
} else {
x = x1;
y = y1;
xEnd = x2;
}
/* put a dot at the position (x, y) */
putpixel(x, y, WHITE);
/* calculate x and y successor and plot the points */
while (x < xEnd) {
x = x + 1;
if (dp < 0) {
dp = dp + twody;
} else {
y = y + 1;
dp = dp + twodxdy;
}
/* put a dot at the given position(x, y) */
putpixel(x, y, WHITE);
/* sleep for 50 milliseconds */
delay(50);
}
getch();
/* deallocate memory allocated for graphic screen */
closegraph();
return 0;
}

ryyker
- 22,849
- 3
- 43
- 87
-
Though I'm not sure what OP's "modified" algorithm is, this surely is just the *original* algorithm? – Jongware Oct 20 '14 at 21:41
-
Who knows? If you show me a vetted original, I will do a diff with this one and tell you. :) – ryyker Oct 20 '14 at 22:26