Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 10 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(3)
我编写了一个可用于处理变换矩阵的网络程序。它允许预设类型和自定义类型。
在线玩或获取源代码。
应该很容易处理这些数字并立即看到它如何影响房屋绘图。查看在线可用的代码以确定它在做什么,您应该能够理解发生了什么。
如果您遇到麻烦,请意识到 3×3 矩阵只是乘以房屋形状中的每个顶点(X 和 Y 坐标)。与顶点的矩阵乘法(我们现在将其称为向量)和变换矩阵看起来像这样......
左边是一个 单位矩阵(不影响向量的幂等矩阵)和 1, 2, 0 的向量(假设它映射到上述程序图中的位置 X1 和 Y2 并忽略最后的
0
)。矩阵乘法可以像这样可视化......
所以,在我们的示例中,这将是......进行
数学运算,我们得到最终的向量...
既然我们说过我们的单位矩阵不应该修改这些值,我们可以在上面看到这种情况,因为结果向量与原始向量相匹配。
为了进一步解释,请考虑何时需要平移向量。假设我们想要将房子沿 X 轴平移
5
像素。我们想从单位矩阵开始,但将右上角的数字更改为5
并在向量中添加额外的维度1
(您很快就会明白原因)。我们再次进行数学计算...
我们可以看到第一个数字(坐标中的 X)已沿 X 轴平移了
5
。在上面链接的程序中尝试一下。我们设置第三个值
1
的原因是,在执行数学运算时,会考虑翻译。如果它是0
,它将被忽略,因为任何数字乘以0
都会得到0
。如果您仍然遇到问题,请查看在线视频(例如这个)这可以帮助以更直观的方式解释它。
请记住:几乎任何人都可以开车,几乎任何人都可以学习这一点,尽管自我评估对数学理解很差。只要坚持下去:坚持是关键。祝你好运。
I wrote a web program that can be used to play around with transformation matrices. It allows preset types and custom ones.
Play with it online or grab the source.
It should be easy to play with the numbers and instantly see how it affects the house drawing. Look at the code available online to determine what it's doing, and you should be able to understand what's going on.
If you're having trouble, realise that the 3×3 matrix is simply being multiplied by each vertex (X & Y coordinate) in the house shape. Matrix multiplication with the vertex (we will now refer to it as a vector) and a transformation matrix looks like so...
On the left is an identity matrix (an idempotent matrix that doesn't affect the vector) and a vector of 1, 2, 0 (assume this maps to position X1 and Y2 in the program mentioned above's graph and ignore the final
0
).Matrix multiplication can be visualised like so...
So, in our example, that would be...
Do that math and we get the final vector...
Since we said our identity matrix shouldn't modify the values, we can see above that that is the case as the resulting vector matched the original.
To explain further, consider when you need to translate the vector. Let's say we want to translate the house by
5
pixels along the X axis. We want to start with the identity matrix, but change the top right number to5
and make the extra dimension in the vector1
(you will see why briefly).We do the math again...
We can see that the first number (X in our coordinates) has been translated along the X axis by
5
. Try it in the program linked above.The reason we made the third value
1
is so when the math was performed, the translation was considered. Had it been0
, it will be ignored, as any number multiplied by0
results in0
.If you're still having trouble, check out videos online (this one, for example) which can help explain it in a more visual fashion.
Remember: pretty much anyone can drive a car, and pretty much anyone can learn this, despite any self-evaluated poor understanding of math. Just keep at it: persistence is key. Good luck.
正如 duffymo 所指出的,矩阵变换只不过是(预)将向量(如 3d 点)乘以矩阵。然而,这是纯数学,对某些人来说很难想象。
理解变换矩阵(至少对我来说)的最佳方法是获取示例代码,让它运行,并玩弄数字。尝试看看是否可以将物体放置得更远,或者旋转 45 度。尝试以不同的顺序进行转换,看看结果是什么。
都在工作吗?好的。
一旦你感受到了这一点,并且如果你有足够的勇气去解决数学问题,你可以采取以下步骤:
首先,了解矩阵乘法是如何工作的。一些链接:
一旦您熟悉了手动乘法矩阵,您就会明白为什么要这样编写变换。当你使用它们时,你最终会理解矩阵。
其次,我总是建议花一个下午的时间尝试实现自己的 Matrix 类并定义一些常见的操作,例如 mul(Vector v)、transpose() 等code> 甚至 createTranslationMatrix(float x, float y, float z)。进行一些测试,看看结果是否与您手工所做的相同。
如果您已经走到这一步,请尝试实施您自己的视角转换!这是我们从未意识到的最令人惊奇的事情。这里有一个有用的解释:
一旦您完成了实现矩阵对象这一最费力但又未被充分重视的任务之一,您将为自己感到非常自豪。祝你好运!
Like duffymo has pointed out, Matrix Transformations is nothing more but (pre)multiplying a vector (like a 3d point) by a matrix. However, that is pure mathematics, and hard for some people to visualise.
The best way to understand transformation matrices (at least for me) is to get an example code, get it running, and play around with the numbers. Try to see if you can place an object farther away, or rotated by 45 degrees. Try putting the transformations in different order and see what the results are.
All working? Good.
Once you get a feel of that, and if you're brave enough to tackle the maths, you could take these steps:
First, understand how matrix multiplications work. Some links:
Once you are comfortable with multiplying a matrix by hand, you will get a feel of why transformations are written that way. As you use them, the understanding of matrices will eventually come to you.
Secondly, I always recommend spending an afternoon trying to implement your own
Matrix
class and define a few common operations likemul(Vector v)
,transpose()
or evencreateTranslationMatrix(float x, float y, float z)
. Put in a few tests and see if the results are the same with what you did by hand.If you've come that far, try implementing your own Perspective Transformation! It's the most amazing thing we never come to appreciate. A useful explanation here:
You will be very proud of yourself once you have accomplished one of the most labourous, yet under-appreciated tasks of implementing a matrix object. Good luck!
变换只不过是一个矩阵乘以一个向量来产生变换后的向量,所以如果你不理解矩阵乘法和加法,你就无法走得太远。
从矩阵和线性代数开始。那里有很多书,但请注意,根据我上面的陈述,您不需要阅读整本书。您不需要特征值或高斯消除或向量空间或任何其他高级和困难的东西。
您只需要知道如何扩展您对矩阵乘法和加法的了解。
获取该转换矩阵中的条目完全是另一回事。您需要一本关于数学和计算机图形学的好书。你不会在线性代数教科书中找到这一点。
A transformation is nothing more than a matrix multiplying a vector to produce the transformed vector, so if you don't understand matrix multiplication and addition you can't get very far.
Start with matricies and linear algebra. There are lots of books out there, but realize that based on the statement that I made above you don't need to read that whole book. You won't need eigenvalues or Gaussian elimination or vector spaces or any of the other stuff that will be advanced and difficult.
You just need to know how to extend what you know about multiplying and adding numbers to matricies.
Getting the entries in that transformation matrix is another matter altogether. You'll need a good book on mathematics and computer graphics. You won't find that in a linear algebra textbook.