Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How is CFrame able to do multiplication with Vector3? [SOLVED]

Asked by 5 years ago
Edited 5 years ago

CFrame and Vector3 are both matrices, but they have a different number of rows and columns. A CFrame is 4x4 matrix and a Vector3 is a 3x1 matrix. According to the standard rules of matrix multiplication, you can only multiply a matrix by another matrix if they have either the same number of rows or the same number of columns (or both). This is where I start to question CFrame's ability to do multiplication with Vector3. Since they have an unequal amount of rows and an unequal amount of columns, I still wonder how they are able to perform multiplication with each other. Maybe it's because Vector3 is, well, a vector, but I still don't know.

local new_mtrx = script.Parent.Base.Position * script.Parent.Joint1.Position

But CFrame is a bit unusual with this. Even though its number of rows and columns is not the same as Vector3's, it can still multiply itself by a Vector3 and evaluate to a Vector3:

local new_vctr = script.Parent.CFrame * script.Parent.Base.Position

And this evaluates to a Vector3. So, my question is:

  • How is CFrame able to multiply itself by a Vector3, and why does it evaluate to a Vector3 instead of throwing an error?

1 answer

Log in to vote
0
Answered by 5 years ago

!enter image description here

Like this. The 4x4 matrix can be multiplied with a 3x1. The top left is the cframe matrix multiplied by the 3x1 vector matrix on the right.

0
That also does not answer my question. The question is "How is it possible?", not "How does it work?". I already know how it works, and I'm asking WHY it works, not HOW it works. DeceptiveCaster 3761 — 5y
0
Hmm, not something I can answer. I am going on a limb here and saying that the vector3 actually gets another value added to make it have 4 when it is multiplied. So the CFrame can actually multiply with a vector3 cause of the equal number of rows. NeutralEnergy -1 — 5y
0
The explanation is fase. The vector is a 4x1 matrix, not a 3x1 matrix. ScriptGuider 5640 — 5y
0
Reasonable. DeceptiveCaster 3761 — 5y
View all comments (3 more)
0
On your educated guess, what do you think the explanation is then? NeutralEnergy -1 — 5y
0
The explanation is that the two matrices are allowed to be multiplied because, in fact, a vector is a 4x1 column matrix instead of 3x1. The 4th row of the CFrame matrix exists to zero-out the position components so that the product 4x1 matrix can reserve it's [x y z 1] structure. And this isn't an educated guess, this is mathematically true. ScriptGuider 5640 — 5y
0
Hmm, so my explanation wasn't wrong. NeutralEnergy -1 — 5y
Ad

Answer this question