M
M
MishkaVNorky2019-09-06 09:30:55
C++ / C#
MishkaVNorky, 2019-09-06 09:30:55

C# and mathematics, who will help transfer the formula to the syntax?

Hello.
Everyone knows the Distance, Magnitude, SqrMagnitude methods in the unit.
Many people know that the fastest option is SqrMagnitude.
I'm interested in optimization in any form, plus I make mobile games.
I found an interesting document, but I'm not an expert in mathematics (
Help me translate the formula into C # syntax.
www.claysturner.com/dsp/FastMagnitude.pdf

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GavriKos, 2019-09-06
@GavriKos

If you are so interested in optimization, you should understand that comparing two values ​​can take longer than a mathematical operation.
Your formula uses max and min. In the classical formula for quadratic distance - only multiplication and addition. Which is faster IMHO. In addition, the dock itself says - the bonus is that the root is NOT USED (yes, the root is an expensive operation).
And - if I read the formula correctly - you still need the lengths of the vectors. Which again is the root and all that.
In general, I'm not sure that this will give an increase, will not give an error (it seems that there is something about this in the dock). And, if you want in optimization, learn math.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question