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

Dividing CFrames/Vector3s seems counterintuitive. Solutions?

Asked by
Psudar 882 Moderation Voter
4 years ago
Edited 4 years ago

Hey guys, I've been focusing a lot more on getting better at manipulating CFrames and I came across something kinda peculiar. I gotta thank people like AxisAngles for both expanding my knowledge and also confusing me even more.

Seemingly, you can multiply a Vector3 into a CFrame like this without error:

Cube.CFrame = CFrame.new(Cube.CFrame * Vector3.new(0, 5, 0))

But when you divide a Vector3;

Cube.CFrame = CFrame.new(Cube.CFrame / Vector3.new(0, 5, 0))

You get an error like this:

19:48:10.072 - attempt to divide a Vector3 with an incompatible value type or nil

In my mind, and I assume a lot of peoples, multiplication and division are inversely related.

I've also read this from AxisAngles:

"If we say that CFrame * Vector3 multiplies a Vector3 out of a CFrame, then we can say that CFrame:inverse() * Vector3 divides a Vector3 into a CFrame."

So doing this:

CFrame:inverse() * Vector3

Implies that its the same as dividing, but whenever you do divide, it throws the value type error.

So what's up with this? Why does it happen?

1 answer

Log in to vote
1
Answered by 4 years ago

It's all matrix math.

There is no such thing as matrix division, which is why you can't use the division symbol with matrices. You can only use their inverse values.

CFrame:inverse() * Vector3 works because of this formula:

A/B = A × (1/B) = A × B^-1

Matrix A is multiplied by the inverse of Matrix B, which is equivalent to division but isn't actually division. It's inverse multiplication.

In terms of CFrame and Vector3, you can perform math on them because CFrame itself contains Vector3 values which can be multiplied by other Vector3 values.

But what is the inverse? Well, the inverse is usually determined in larger matrices like CFrame through something called elementary row operations. Elementary row operations are the acts of swapping, multiplying and adding rows. More about that here.

Mutliplying an inverse by a matrix can be considered indirect division, although it still isn't really division.

0
Thanks a ton mate. This makes a lot more sense when you put the actual size of matrixes into perspective. Never even thought of that. Psudar 882 — 4y
Ad

Answer this question