Tuesday, May 20, 2008

Assingment #3, Question 3

For this question we have to extend question #2 to 3 colours c1, c2, c3 and find the relative percentages of each colour in composing a given colour c that is found within the triangle formed by c1, c2, c3.

We can use the general expression for finding the relative percentagies of c1 and c2 found in question 2; namely,

(x,y) = m1(x1, y1) + m2(x2, y2), where m1 is the decimal representation of distance(c1, c)/distance(c1, c2) and similarly m2 = distance(c, c2)/distance(c1, c2).

Another way we can think about this is that if we multiply m1 by x1 and m2 by x2, then add these two products together, then we will get the x-value for the colour 'c', which lays on the straight line between c1 and c2. Similarly for c's y-value.

Now extend this to 3 colours.

(x,y) = m1(x1, y1) + m2(x2, y2) + m3(x3, y3).

Note that m3 = 1 - m1 - m2 since we are dealing with fractions of 3 contributing colours that compose the colour c, which lays within a triangle whose vertices are c1, c2, c3. The percentage of each colour in the composition of colour 'c' will be 100% or 1. I will use 1.

So,

x = m1x1 + m2x2 + m3x3 (1)

y = m1y1 + m2y2 + m3y3 (2)

=> x = m1x1 + m2x2 + (1-m1-m2)x3 (1)

=> y = m1y1 + m2y2 + (1-m1-m2)y3 (2)

Solving for m1 in equation 1 you get:

m1 = [x - x3 - m2 (x2-x3)] / (x1 - x3)

Sub m1 into equation (2) and solve for m2:

m2 = (-x1y+x3y+xy1-x3y1-xy3+x1y3) / (x2y1-x3y1-x1y2+x3y2-x2y3+x1y3)

Once you have m1 and m2, solve for m3 by using m3 = 1 - m1 - m2.

So to find the relative percentages all you need to know are the coordinates for c1(x1, y1), c2(x2, y2), c3(x3, y3) and c(x,y).

No comments: