Why is my own magnitude VS roblox magnitude not the same?

Is this some sort of floating point error? I tried to do my own magnitude calculation but it’s off from the roblox’s magnitude

Can you provide the script?

Under limit.

Your equation is wrong. Don’t absolute the components before doing the subtraction inside the square.

1 Like

Why is it wrong? It’s still the same as the roblox magnitude until the fifth decimal

Because if you have vectors

(1, 2, -3) and (4, 5, 6)

The vector between them is (3, 3, 9) not (3, 3, 3). Your equation would imply it’s the latter.

You might have got lucky with the vectors you chose to use, but it is not the correct equation to absolute the components before the subtraction.

The correct equation is

m = math.sqrt( (x2-x1)^2 + (y2-y1)^2 + (z2-z1)^2 )

The error in the decimals is likely due to raising to the double 1/2 as additional floating point error will be added here I believe. Try 0.5 and math.sqrt() and compare the outputs to the 1/2 and the built-in.

1 Like