Add more CFrame operations to improve logical flow

As a Roblox developer, it is somewhat inconvenient and often times confusing to use the Inverse function with CFrames.

If Roblox is able to address this issue, it would improve my development experience because it would allow me to think of CFrames in a more mathematical way and would resolve some common confusion with users who are new to CFrames. This would additionally greatly reduce the amount of characters you would need to type.

(I need to update these to use the suggestion below)
Some examples which can support implementation of these operators:

local cfa = cf1 / cf2 -- Equivalent to cf1 * cf2:Inverse()
local cfb = -cf1 -- Equivalent to cf1:Inverse()
local cfc = cf1 * -cf2 -- Equivalent to cfa, however more clumsy thus reinforcing the division operator. Additionally does not work algebraically although they are equal.
local cfd = (cf1 * cf2) / cf2 -- This now works algebraically!
local cfe = -cf2 * cf1 -- NOT equivalent to cfa. Additionally reinforced because this does not work algebraically.
-- Previously this would look like this: cf2:Inverse() * cf1.
-- This messes with my logical flow sometimes especially because this looks similar to cf1 * cf2:Inverse() even though they are not equal.
6 Likes

It would be more confusing to use division on CFrames because your usual notion of division is not a thing with matrix operations. This would make dividing CFrames behavior confusing up-front.

This inherently breaks the idea of thinking about matrices in a mathematical way when it makes the code less readable.

5 Likes

I somewhat agree but I personally don’t think of CFrames like a matrix since they don’t behave particularly the same. CFrames act more like an object (like a vector) and have many utility functions not specific to matrices.

Additionally in my examples I point out that making things work more algebraically might reduce confusion. Algebra is a pretty common concept also used in programming and is easily understood (it’s taught in middle school and sometimes upper elementary in the US).

When it comes to readability I agree that it does become a little less speech-like however I think the logical tradeoff is worth it. It’s not much different than how Vector3s behave other than the usage of multiplication and division instead of addition/subtraction.

Additionally (I’ve seen this argument before) I think that addition/subtraction wouldn’t work in this case due to the seperation of unary (inverse) and non-unary having better algebraic logic and I think it would end up being cluttered having multiplication and addition function in the same way.

1 Like

I see where you are coming from, I am just not a fan of too much implicit behavior.

Yes, this is due to the nature of what the matrix is trying to describe.

I’d like to know what Roblox’s philosophy is when it comes to API standards. Its weird we don’t have a public one.

1 Like

Unary minus for inverse doesn’t make much sense.

Inverse of a matrix is usually described as m^(-1), not -m.

a*a^(-1) = i

This works for matrices, and normal numbers.
If you do -a instead of a^(-1)

a*(-a) = i

This doesnt work with normal numbers.
And then…

-a = a^(-1)

2 Likes

I think this is a better alternative! It avoids getting rid of the algebraic benefits and works algebraically. It also resolves a few other issues with unary.