0

我對WPF轉換類的理解是Matrixrepresents a 3x3 row-major matrix of 2D homogenised coordinates where the final column is always(0,0,1)。我理解這種設計的原因是爲了便於翻譯表示爲矩陣乘法,就像旋轉,縮放和傾斜變換一樣,而不是單獨作爲矢量,如果使用2×2矩陣則必須是這種情況。Vector.Multiply忽略矩陣的偏移值

因此,我的期望是,當包含翻譯的Matrix的multiplying a Vector應該翻譯結果向量。在使用WPF矩陣類時,這似乎並沒有發生,所以我做錯了什麼?

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); 

結果:

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

回答

1

現在我明白了。 VectorPoint之間的區別很重要。我應該使用Points和Point.Multiply來代替,然後結果就是我所期待的。矢量是兩點之間的差異,不受翻譯的影響,而點是受影響的特定位置。

+0

對,但回答你自己的問題是否可以肯定? – 2013-05-02 19:15:33

+0

是的,它的建議。它可以節省其他人花時間在上面,並幫助其他人面臨同樣的問題。 – 2013-05-02 22:26:33