如何将 2D 点与 4D 矩阵相乘 [英] How to multiple a 2D point with a 4D Matrix

查看:28
本文介绍了如何将 2D 点与 4D 矩阵相乘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用 4D 矩阵将 2D 点(或 Z=0 的 3D)转换为 2D 点(其中 Z 被忽略)?

How can I convert a 2D point (or 3D with Z=0) to 2D point(where Z is ignored) with a 4D matrix ?

我正在使用 Microsoft 的 Silverlight 使用 Matrix3D 将 2D 控件投影为伪 3DMatrix3D 的定义

I am using Microsofts Silverlight to project a 2D control as pseudo 3D using a Matrix3D definition of Matrix3D

我知道未变换控件中点的初始 2D 坐标,并且我想要变换后该点的 2D 位置.

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.

关于 3D 方法的 Silverlight API 很少.

The silverlight API is sparse regarding 3D methods.

请建议基本的数学来执行计算.

Please suggest basic math to perform the calculation.

这是silverlight 特定问题

编辑更多细节

它不起作用.我正在使用

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

输入 x 和 y 为 0,0,结果 x,y 为 0, 58.5786矩阵是

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

在 Z 轴上产生 45 度角旋转,其中旋转点是平面的底部.

that produces a 45 degree angle rotation in Z where the rotation point is the bottom of the plane.

包括 OffsetX 在内的所有 M1n 值都是 0.0,因此 x 始终是原始值.

all the M1n values including OffsetX is 0.0 resulting in x always being the original value.

我做错了什么?

这是我的四个示例值以及上述数学运算的结果

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

查看生成的图像,400x400 平面的左上角为 45,135,右上角为 355,135,左下角为 0,400,右下角为 400,400

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

所以对于 0,0,0,1.0 的测试值,我希望 x 和 y 为 45,135

so for the test value of 0,0,0,1.0 I would expect x and y to 45,135

推荐答案

将您的 2D 向量扩展为 4D 向量 - (X, Y, 0, 1);这是在 齐次坐标中指定的 3D 矢量.将 4D 向量乘以 4D 矩阵,从而得到一个新的 4D 向量,您可以从中获取前 2 个分量.

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.

如果矩阵指定了某种透视投影,那么你需要除以最后一个分量,即如果你的结果向量是 (x, y, z, w),那么最终坐标是 (x/w, y/w, z/w).如果矩阵没有透视投影,那么 w = 1,最终向量就是 (x, y, z)

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)

这篇关于如何将 2D 点与 4D 矩阵相乘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆