|
From: Daniel J S. <dan...@ie...> - 2007-02-07 14:02:12
|
Hans-Bernhard Bröker wrote: > Daniel J Sebald wrote: > >>I've looked through the code a bit and your examples. (What command >>does one need to compile this program?) I'd have to think about your >>approach to be certain about the result. You've broken the thing down >>into a series of one dimensional linearities, first along the sides of >>the triangle to get a color, and then across the x dimension to further >>interpolate between those two. Seems logical, but it may be open for >>rounding problems. > > > And, more importantly, it's a bit biased, which tends to turn into a > robustness problem. The bias lies in the arbitrary choice of one vertex > to be shared by the two first interpolations. > > It can be better to go via barycentric coordinates. It's effectively a > method to find three numbers s, t, and u such that: > > s+t+u=1 > s*A + t*B + u*C = X for the point, and its colour. > > I.e. you solve the equation for s,t,u given a point X, then substitute > them into the equation to find the target colour. Interesting. This results in matrix equations similar to what I sent previously: s * x_1 + t * x_2 + u * x_3 = x s * y_1 + t * y_2 + u * x_3 = y s * 1 + t * 1 + u * 1 = 1 or | x_1 x_2 x_3 | | y_1 y_2 y_3 | | 1 1 1 | (call it Z) product with [s t u]' equals [x y 1]' so [s t u]' = inv(Z) [x y 1]' Since I doubt you'd want to compute the intermediate values s t u for each pixel inside the triangle c = [c_1 c_2 c_3] * [s t u]' = [c_1 c_2 c_3] * inv(Z) * [x y 1]' = [w_1 w_2 b] * [x y 1]' = w' * [x y]' + b Dan |