affine_map_tri.txt map a triangle with vertices x0,y0 x1,y1 x2,y2 onto a right regular triangle 0,0 1,0 (in a) 0,1 (in b) and inverse map x2,y2 o** * *** * ***o x1,y1 * **** x0,y0 o**** b 0,1 o ** * * * * * * 0,0 o*******o a 1,0 x = c0 + c1*a + c2*b y = c3 + c4*a + c5*b x0 = c0 + c1*0 + c2*0 thus c0 = x0 y0 = c3 + c4*0 + c5*0 thus c3 = y0 x1 = x0 + c1*1 + c2*0 thus c1 = x1-x0 y1 = y0 + c4*1 + c5*0 thus c4 = y1-y0 x2 = x0 + (x1-x0)*0 + c2*1 thus c2 = x2-x0 y2 = y0 + (y1-y0)*0 + c5*1 thus c5 = y2-y0 thus the mapping from a,b to x,y is: x = x0 + (x1-x0)*a + (x2-x0)*b a in 0 .. 1 y = y0 + (y1-y0)*a + (y2-y0)*b b in 0 .. 1-a This mapping: does not preserve area, does not preserve angle, is a full covering rewriting the mapping in matrix form: |(x1-x0) (x2-x0)| * |a| = |(x-x0)| |(y1-y0) (y2-y0)| |b| = |(y-y0)| solving the simultaneous equations for a and b y *(x2-x0)-x *(y2-y0)+x0*y2-y0*x2 a = --------------------------------- y1*(x2-x0)-x1*(y2-y0)+x0*y2-y0*x2 x *(y1-y0)-y *(x1-x0)+x1*y0-y1*x0 b = --------------------------------- x2*(y1-y0)-y2*(x1-x0)+x1*y0-y1*x0 map a triangle with vertices x0,y0 x1,y1 x2,y2 onto a right regular triangle -1,-1 1,-1 (in a) -1,1 (in b) and inverse map x2,y2 o** * *** * ***o x1,y1 * **** x0,y0 o**** b -1,1 o ** * * * * * * -1,-1 o*******o a 1,-1 x = c0 + c1*a + c2*b y = c3 + c4*a + c5*b (x1+x2)/2 = 0 in a (y1+y2)/2 = 0 in b for checking x0 = c0 + c1*(-1) + c2*(-1) |1 -1 -1| |c0| |x0| y0 = c3 + c4*(-1) + c5*(-1) |1 1 -1|*|c1|=|x1| |1 -1 1| |c2| |x2| x1 = c0 + c1*1 + c2*(-1) y1 = c3 + c4*1 + c5*(-1) |1 -1 -1| |c3| |y0| x2 = c0 + c1*(-1) + c2*1 |1 1 -1|*|c4|=|y1| y2 = c3 + c4*(-1) + c5*1 |1 -1 1| |c5| |y2| c0 = x0 + (x1-x0)/2 + (x2-x0)/2 c1 = (x1-x0)/2 c2 = (x2-x0)/2 c3 = y0 + (y1-y0)/2 + (y2-y0)/2 c4 = (y1-y0)/2 c5 = (y2-y0)/2 thus the mapping from a,b to x,y is: x = x0 + (x1-x0)/2 + (x2-x0)/2 + ((x1-x0)/2)*a + ((x2-x0)/2)*b a in -1..1 y = y0 + (y1-y0)/2 + (y2-y0)/2 + ((y1-y0)/2)*a + ((y2-y0)/2)*b b in -1..-a This mapping: does not preserve area, does not preserve angle, is a full covering a = d0 + d1*x + d2*y b = d3 + d4*x + d5*y -1 = d0 + d1*x0 + d2*y0 |1 x0 y0| |d0| |-1| -1 = d3 + d4*x0 + d5*y0 |1 x1 y1|*|d1|=| 1| |1 x2 y2| |d2| |-1| 1 = d0 + d1*x1 + d2*y1 -1 = d3 + d4*x1 + d5*y1 |1 x0 y0| |d3| |-1| -1 = d0 + d1*x2 + d2*y2 |1 x1 y1|*|d4|=|-1| 1 = d3 + d4*x2 + d5*y2 |1 x2 y2| |d5| | 1| y *(x2-x0)-x *(y2-y0)+x0*y2-y0*x2 a = 2*--------------------------------- - 1 y1*(x2-x0)-x1*(y2-y0)+x0*y2-y0*x2 x *(y1-y0)-y *(x1-x0)+x1*y0-y1*x0 b = 2*--------------------------------- - 1 x2*(y1-y0)-y2*(x1-x0)+x1*y0-y1*x0