通过矩阵平移向量
我有一个 4*4 矩阵和一个 3d 向量。 我需要通过矩阵翻译我的向量。
请不要太多疯狂的数学符号,因为我不明白。
一个接近java的例子就太棒了!
I have a 4*4 matrix and a 3d vector.
I need to translate my vector by the matrix.
Not too much crazy maths notation please because I don't understand it.
An example in something close to java would be fab!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
一旦你看到它,就很容易了。
意味着...
意味着...
d1-d4 可以生成“1”,因此您不需要使用它。
希望这有帮助。
It quite easy once you see it.
means ...
means ...
d1-d4 are there to make '1' so you don't need to use it.
Hope this helps.
不过,你需要数学。我会尽量温和,但如果你不知道如何进行矩阵乘法,你需要立即查一下!
首先,您需要通过添加额外的 1 将 3D 向量变成 4 向量。计算机图形学通常将其称为“w”坐标(与 x、y 和 z 坐标配合)。
3D矢量:(X,Y,Z) -> 4D 向量:(x=X, y=Y, z=Z, w=1)
然后,您可以将 4 向量乘以 4x4 矩阵。它的作用取决于矩阵——但是你可以创建一个平移向量的矩阵:
毫不奇怪,这种矩阵被称为平移矩阵。
这样做的好处是,您还可以创建一个旋转矩阵或缩放矩阵,然后您可以将任意数量的它们相乘成一个矩阵:
将向量乘以得到的矩阵相当于按顺序乘以所有分量矩阵,正如您想象的那样,这可以节省您大量的时间和麻烦。
将 4 向量乘以 4x4 矩阵的代码可能类似于:
You need the maths, though. I will try to be gentle, but if you don't know how to do matrix multiplication, you need to look it up, right now!
First, you need to make your 3D vector into a 4-vector, by adding an extra 1 to it. Computer graphics usually calls this a "w" coordinate (to go with the x, y, and z coordinates).
3D vector: (X,Y,Z) -> 4D vector: (x=X, y=Y, z=Z, w=1)
Then, you can multiply the 4-vector by the 4x4 matrix. What this does depends on the matrix -- but you can make a matrix that translates the vector:
Unsurprisingly, this kind of matrix is called a translation matrix.
The advantage of doing things this way is that you can also make a rotation matrix, or a scaling matrix, then you can multiply as many of them as you want together into one matrix:
Multiplying a vector by the resulting matrix is equivalent to multiplying by all the component matrices in sequence, which as you might imagine can save you a lot of time and hassle.
Code for multiplying a 4-vector by a 4x4 matrix might be something like:
如果您将(通常是 3d)向量 (x, y, z) 视为四向量 (x, y, z, 1),您可以这样做:
w = Av
T
,其中T
是转置操作(垂直扭曲水平向量,反之亦然),A
是正确选择的矩阵,w
是转换后的矩阵。您必须知道如何进行矩阵乘法。
要通过
(a, b, c)
获得转置,而无需将A
定义为:If you treat your (generally 3d) vector (x, y, z) as a four vector (x, y, z, 1) you can do this:
w = Av
T
, whereT
is the transpose operation (twist a horzontal vector vertical or vice versa) andA
is a correctly chosen matrix, andw
is the translated matrix.You do have to know how to do matrix multiplication.
To get a transposition by
(a, b, c)
and nothing else defineA
as:我不确定您的数据到底以什么形式出现,但乍一看,您可能正在处理
无需太深入数学,有几种方法可以表示三维矩阵变换。有欧拉角和四元数。欧拉角肯定更简单,但四元数具有不易受万向节锁定影响的优点。
三维实值的四元数用 4x4 矩阵表示,这就是为什么我认为这可能适用于您。当然,其他解决方案的作者可能是正确的,您正在处理的内容可能完全不同,但无论如何它可能值得学习。
希望这有帮助。祝你好运!
I'm not sure exactly what form your data is coming in but just on first glance it looks like you might be dealing with quaternions.
Without getting too deep into the math, there are a couple ways to represent a three dimensional matrix transform. There are Euler angles and quaternions. Euler angles are definitely simpler but quaternions have the advantage of not being susceptible to gimble lock.
Quaternions of real values in three dimensions are represented with 4x4 matrices which is why I thought this may apply to you. Of course, the authors of the other solutions may be right and what you're dealing with could be something totally different but it might be worth learning about anyway.
Hope this helps. Good luck!