Bresenham's line algorithm and image rescaling with nearest-neighbor interpolation and bilinear interpolation. Part of a series teaching game programming. Visit codeschool.org
You have no idea how much of a relief this was to watch, most of the sources i found on the internet treated bilinear transform with a matrix approach, i just wanted an example damn it !
Gosh... I remember in the 70's looking at the code in the Apple II and learning this graphics algorithm from the code that was in the ROM part of their OS.
What you were explaining in the video is an incremental error algorithm, but NOT the Bresenham algorithm. It is not precise because of the usage of floating-point representation could cause computed points to drift away from their actual position when the line is relatively long. The code you wrote does not use the floating-point multiplication which makes it faster than the direct implementation using the line equation, however, it does use the floating-point addition. On the other hand, Bresenham’s approach allows integer-only arithmetic, which is generally faster than using floating-point arithmetic.
great video, help me a lot. I think there are some mistakes in the actual interpolation resultat @12:35, the result should be 0 0 1 1 2 3 3 4 instead of 0 0 1 2 2 3 4 4. those integers represents the source cells' colors.
Hi there, did you notice you can go around floats to? You just need three booleans, which indicate, wether delta is negative. Lets call them xDecr, yDecr and slopeNegative. C-Language: If (xDecr != yDecr) slopeNegative = true; // XOR "^" would be the same if (delta.x == delta.y) // slope = 1 [...code...] else if (delta.x > delta.y) // slope < 1 [...code...] else // slope > 1 [...code...]
This line drawing algorithm is annoying to implement when you want to be able to clamp the points to the edges of the screen when you're passing points _outside_ the screen space. I was playing around with projecting 3d points onto a 2d screen, and when the 3d points were close to the camera, the projected 2d points would "explode" in magnitude out towards a billion or something and when you don't clamp to the screen, you're iteration over the line drawing routine a billion times which isn't ideal. I did implement clamping for the slow version correctly which is nice, but it's less obvious with Bresenham's algorithm.
Omg... is this it? C'mon isn't this the best example on why you would want to represent polynomials as vectors? Each coeficient is a derivative/n! with n = position so you run adding them until you add to the position as in euler integration and you can figure out the y increment and the rest goes as usual. So you plot any polynomial...