Question

My understanding of the WPF transformation classes is that the Matrix class represents a 3x3 row-major matrix of 2D homogenised coordinates where the final column is always (0,0,1). I understand that the reason for this design is to facilitate translations to be represented as matrix multiplications, in the same way as rotate, scale and skew transformations, rather than separately as vectors, which would have to be the case if 2x2 matrices were used.

My expectation therefore is that when multiplying a Vector by a Matrix that contains a translation, the resultant vector should be translated. This does not seem to be happening for me when using the WPF matrix classes, so what am I doing wrong?

Matrix m = new Matrix();
m.Translate(12, 34);

Vector v = new Vector(100, 200);
Vector r = Vector.Multiply(v, m);

// Confirm that the matrix was translated correctly
Debug.WriteLine(m);

// Confirm that the vector has been translated
Debug.WriteLine(r);

Results:

1,0,0,1,12,34    // Matrix contains translation as expected
100,200          // Vector is unchanged - not expected
Was it helpful?

Solution

I see now. The distinction between a Vector and a Point is important. I should be using Points and Point.Multiply instead, and then the results are what I was expecting. A vector is the difference between two points, which is unaffected by a translation, whereas a point is a specific location which is affected.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top