Use of offsets for translation in Matrix3D

时间:2015-12-04 21:18:32

标签: c# wpf matrix 3d

I have an application where I want to scale, rotate, and translate some 3D points.

I'm used to seeing 3x3 rotation matrices, and storing translation in a separate array of values. But the .Net Matrix3D structure ( https://msdn.microsoft.com/en-us/library/System.Windows.Media.Media3D.Matrix3D%28v=vs.110%29.aspx) is 4x4 and has a row of "offsets" - OffsetX, OffsetY, OffsetZ, which are apparently used for translation. But how, exactly, are they intended to be applied?

Say I have a Vector3D with X, Y, Z values, say 72, 24, 4. And say my Matrix3D has

.707   0   -.707   0
0      1     0     0
.707   0   .707    0
100   100    0     1

i.e., so the OffsetX and OffsetY values are 100.

Is there any method or operator for Matrix3D that will apply this as a translation to my points? Transform() doesn't seem to. If my code has . . .

Vector3D v = new Vector3D(72, 24, 0);
Vector3D vectorResult = new Vector3D();
vectorResult = MyMatrix.Transform(v);

vectorResult has 8.484, 24, -8.484, and it has the same values if the offsets are 0.

Obviously I can manually apply the translation individually for each axis, but I thought since it's part of the structure there might be some method or operator where you give it a point and it applies the entire matrix including translation. Is there?

1 个答案:

答案 0 :(得分:2)

4x4矩阵表示使用齐次坐标的3D空间变换。在此表示中,w组件被添加到向量中。该组件根据向量应表示的内容而不同。用矩阵变换向量是简单的乘法:

transformed = vector * matrix

(两个向量都是行向量)。

w组件仅由矩阵'最后一行 - 存储翻译的部分。因此,如果要转换点,则此组件必须为1.如果要转换方向,则此组件必须为0(因为如果转换它们,方向向量不会更改)。

这种差异用WPF中的两种不同结构表示。 Vector3D表示方向(w组件0),Point3D表示点(w组件1)。因此,如果您将v设为Point3D,那么一切都应该按预期运行。