如何将 2D 点与 4D 矩阵相乘
如何使用 4D 矩阵将 2D 点(或 Z=0 的 3D 点)转换为 2D 点(其中 Z 被忽略)?
我正在使用 Microsoft Silverlight 使用 Matrix3D 将 2D 控件投影为伪 3D Matrix3D 的定义
我知道未变换控件中某个点的初始 2D 坐标,并且我想要变换后该点的 2D 位置。
silverlight API 关于 3D 方法的内容很少。
请建议进行计算的基本数学知识。
编辑更多详细信息,
但它不起作用。 我正在使用
x = x0 * matrix[0][0] + y0 * matrix[1][0] + z0 * matrix[2][0] +
w0 * matrix[3][0];
y = x0 * matrix[0][1] + y0 * matrix[1][1] + z0 * matrix[2][1] +
w0 * matrix[3][1];
z = x0 * matrix[0][2] + y0 * matrix[1][2] + z0 * matrix[2][2] +
w0 * matrix[3][2];
,输入 x 和 y 为 0,0,结果 x,y 为 0, 58.5786 该矩阵
HasInverse true bool
IsIdentity false bool
M11 1.0 double
M12 0.0 double
M13 0.0 double
M14 0.0 double
M21 0.0 double
M22 0.70710676908493042 double
M23 0.70710676908493042 double
M24 0.0 double
M31 0.0 double
M32 -0.70710676908493042 double
M33 0.70710676908493042 double
M34 0.0 double
M44 1.0 double
OffsetX 0.0 double
OffsetY 58.578643798828125 double
OffsetZ -141.42135620117187 double
在 Z 轴上产生 45 度角旋转,其中旋转点是平面的底部。
所有 M1n 值(包括 OffsetX)均为 0.0,导致 x 始终为原始值。
我做错了什么?
这是我的四个示例值,上面的数学结果
0, 0, 0, 1 -> 0, 58.5786437988281, -141.421356201172, 1
50, 0, 0, 1 -> 50, 58.5786437988281, -141.421356201172, 1
0, 100, 0, 1 -> 0, 129.289320707321, -70.7106792926788, 1
100, 100, 0, 1 -> 100, 129.289320707321, -70.7106792926788, 1
查看结果图像,400x400 平面的左上角为 45,135,右上角为 355,135,左下角为 0,400,右下角为 400,400,
因此对于测试值 0, 0,0,1.0 我期望 x 和 y 为 45,135
How can I convert a 2D point (or 3D with Z=0) to 2D point(where Z is ignored) with a 4D matrix ?
I am using Microsofts Silverlight to project a 2D control as pseudo 3D using a Matrix3D
definition of Matrix3D
I know the initial 2D coordinate of a point in the untransformed control and I want the 2D position of the point after the transform.
The silverlight API is sparse regarding 3D methods.
Please suggest basic math to perform the calculation.
This is a follow on from a silverlight specific question
Edit further details
its not working.
I am using
x = x0 * matrix[0][0] + y0 * matrix[1][0] + z0 * matrix[2][0] +
w0 * matrix[3][0];
y = x0 * matrix[0][1] + y0 * matrix[1][1] + z0 * matrix[2][1] +
w0 * matrix[3][1];
z = x0 * matrix[0][2] + y0 * matrix[1][2] + z0 * matrix[2][2] +
w0 * matrix[3][2];
and the input x and y are 0,0 and the result x,y are 0, 58.5786
the matrix is
HasInverse true bool
IsIdentity false bool
M11 1.0 double
M12 0.0 double
M13 0.0 double
M14 0.0 double
M21 0.0 double
M22 0.70710676908493042 double
M23 0.70710676908493042 double
M24 0.0 double
M31 0.0 double
M32 -0.70710676908493042 double
M33 0.70710676908493042 double
M34 0.0 double
M44 1.0 double
OffsetX 0.0 double
OffsetY 58.578643798828125 double
OffsetZ -141.42135620117187 double
that produces a 45 degree angle rotation in Z where the rotation point is the bottom of the plane.
all the M1n values including OffsetX is 0.0 resulting in x always being the original value.
What am I doing wrong ?
Here are my four example values with the results of the above math
0, 0, 0, 1 -> 0, 58.5786437988281, -141.421356201172, 1
50, 0, 0, 1 -> 50, 58.5786437988281, -141.421356201172, 1
0, 100, 0, 1 -> 0, 129.289320707321, -70.7106792926788, 1
100, 100, 0, 1 -> 100, 129.289320707321, -70.7106792926788, 1
looking at the resulting image the 400x400 plane has a top left of 45,135 and top right of 355,135, bottom left is 0,400 and bottom right is 400,400
so for the test value of 0,0,0,1.0 I would expect x and y to 45,135
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将 2D 向量展开为 4D 向量 - (X, Y, 0, 1);这是在齐次坐标中指定的 3D 矢量。将 4D 向量乘以 4D 矩阵,从而得到一个新的 4D 向量,从中获取前 2 个分量。
如果矩阵指定某种透视投影,那么您需要除以最后一个分量,即如果您的结果向量是(x,y,z,w),那么最终坐标是(x / w,y / w,z/w)。如果矩阵没有透视投影,则 w = 1,最终向量就是 (x, y, z)
Expand your 2D vector to a 4D vector - (X, Y, 0, 1); this is a 3D vector specified in homogeneous coordinates. Multiply the 4D vector by the 4D matrix thus getting a new 4D vector, from which you take the first 2 components.
If the matrix specifies some kind of perspective projection, then you'll need to divide by the last component, i.e. if your resulting vector is (x, y, z, w), then the final coordinates are (x/w, y/w, z/w). If the matrix doesn't have a perspective projection, then w = 1 and the final vector is just (x, y, z)
我不确定是否有捷径,但您想要的是:(
假设您的 oldZ 为零,并且您将忽略 newZ 值)。
编辑:更好的方法是:
您的新坐标是:
newPos.X
和newPos.Y
;I'm not sure if there's a shortcut for this but what you want is:
(assuming that your oldZ is zero and you're going to ignore the newZ value).
Edit: A better way to do it is:
Your new coordinates are:
newPos.X
andnewPos.Y
;