Reputation: 1084
I'm trying to draw a curve between two points, specifically I leave a picture of what I want:
This image was taken from this pdf on page 10.
I understand that applies the concept of Bresenham algorithm
but do not know how to implement the concept for draw the curve.
On page 11 of the pdf pseudocode algorithm
shown, but do not understand the concept of "error" to implement. Please if anyone can help me understand this. I work with C ++ and OpenGL.
Pseudocode:
set up x, y to x0, y0
set up error variable exy for P(x0+1,y0+1)
loop
set pixel x, y
if ex + exy > 0 then increment x, sub difference error
if ey + exy < 0 then increment y, add difference error
loop until end pixel
Thanks you all.
Upvotes: 1
Views: 3371
Reputation: 253
This paper you cited draws curves from a low level of abstraction to try to gain performance increases. Normally when you go to draw curves you should use a higher abstraction such as Beziers with De Casteljau's algorithm which your pdf mentions on page 22. I've done this in c++ and it's not hard at all. Pomax has an awesome guide that explains it well. You basically subdivide your curve until it's many straight lines looks curved. Then you draw all the straight lines.
Upvotes: 3
Reputation: 295
The idea of this algorithm is that you define your curve by a function f(x, y) = 0
. That is to say that the function f(x, y)
should return zero for the (x, y)
coordinates of any point which lies on the curve. For any point which does not lie on the curve, the function should return a nonzero value, whose magnitude and sign should indicate the distance and direction, respectively, of the given point from the curve. This value is referred to as “error”.
Thus, the “error” value for any pixel can be computed simply by calling f(x, y)
for the (x, y)
coordinates of the pixel in question.
Upvotes: 1