In: Computer Science
Given a pixel location (x1, y1), we can calculate z_i for this point as (d- ax1- by1)/c. This takes 2 multiplications and a division for each pixel. Suppose the z_i value for (x1, y1) is known,
find an easier way to find the z_i for (x1+1, y1) and (x1, y1+1) (pixels bordering (x1, y1))?
Does this lead to a more efficient way of calculating z_i for each pixel? Explain.
z_i = (d - ax1 - by1)/c.
Here, 2 multiplications -> a*x1 and b*y1
and 2 divisions -> a*x1/c and b*y1/c
are used. But when we know z_i value for (x1,y1), it will take less number of operations to calculate z+i of (x1+1,y1) and (x1,y1+1).
Let z_i of (x1+1,y1) be zi_new and z_i of (x1,y1) be zi. So,
zi_new - zi = (d - a(x1+1) - by1)/c - (d - ax1 - by1)/c = -a/c
zi_new - zi = -a/c
zi_new = zi - a/c
So, given zi, we only need one division and one subtraction operation to find zi_new. Hence, given z_i of (x1,y1), it is very easy and efficient to calculate z_i of (x1+1,y1).
Similarly for (x1,y1+1), we will get
zi_new = zi -b/c.
So, it is efficient to calculate z_i of both (x1+1,y1) and (x1,y1+1) when z_i of (x1,y1) is present.
Starting from the bottom-left pixel of the image, calculate z_i using the formula, z_i = (d - ax1 - by1)/c. After that calculate z_i of a neighbor pixel by using the formula, zi_new = zi - a/c, for pixel right of the current pixel and zi_new = zi -b/c for pixel above of the neighbor pixel. This new calculated z_i will in turn be used to calculate z_i of its neighbor and hence, each pixel's z_i(other than bottom left) can be calculated with just one division and one subtraction operation in each caluculation.
Therefore, calculating z_i value of current pixel from the neighboring pixel is very much more efficient than calculating z_i through this formula (d- ax1- by1)/c.