如何将多个二维点与四维矩阵 [英] How to multiple a 2D point with a 4D Matrix

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

问题描述

我怎么能转换成一个2D点(或3D与Z = 0)到二维点(其中Z被忽略)与四维矩阵?

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

我使用微软的Silverlight项目使用的Matrix3D二维控制伪3D <一href="http://msdn.microsoft.com/en-us/library/system.windows.media.media3d.matrix3d%28v=vs.95%29.aspx"相对=nofollow>的Matrix3D 定义

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.

Silverlight的API是稀疏的关于3D的方法。

The silverlight API is sparse regarding 3D methods.

请提出基本的数学进行计算。

Please suggest basic math to perform the calculation.

这是从<一个一个遵循href="http://stackoverflow.com/questions/5017990/how-can-i-get-a-2d-point-from-a-matrix3d-in-silverlight">silverlight具体问题

修改的详细信息

它不工作。 我使用

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

这产生了45度角旋转在-Z其中旋转点是平面的底部。

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

所有M1N值,包括OffsetX是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的平面有45135顶左,355135右上,左下是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以45135

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);这是指定的三维矢量齐次坐标。通过四维矩阵从而获得了新的4D向量,从中取前2组件乘4D向量。

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)

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

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