#To get the actual magnitude
1 messages · Page 1 of 1 (latest)
For convenience
im not getting core difference of it
i know pythagoras theorem and all in maths but not getting this
it'd be inconvenient to write the sqrt every time
There's no difference between taking .sqrMagnitude and calling sqrt yourself vs just .magnitude
so there's a shortcut
you can compute sqrMagnitude yourself too if you want. you could make Vector2s or Vector3s yourself if you want
but these are common things, so unity provides them for us
ahhhhhhhhhhhh im not getting this broðŸ˜
I'm confused about what you're confused about now tbh
i need a video tutorial of this i guess
Yeah that's exactly it. Look at Pythagorean theoremsl
im just not getting the core difference between them
i know pythagoras theorem
sqrMagnitude is Pythagorean theorem without the sqrt over everything.
Magnitude is with the sqrt
That's it
the only difference is one is squared
Or rather, not square rooted
thats alll???????
Yes
that's what we've been saying the entire time
i just got it right now 🥲
but can you explain what will be difference between them?
one is squared
nooo i mean in their calculated values
yes, one will be squared
The reason to use sqrMagnitude sometimes is because the squared version is good enough for a lot of things without having to do the square root operation which is slow. For example just determining if magnitude is nonzero, or seeing which vector is longer (when comparing two vectors), you can do with the square magnitude, and it's faster.
hmmmmm 
huh, wonder why that doesn't go to the actual lines
it's at line 201 to 204
// Returns the length of this vector (RO).
public float magnitude { [MethodImpl(MethodImplOptionsEx.AggressiveInlining)] get { return (float)Math.Sqrt(x * x + y * y); } }
// Returns the squared length of this vector (RO).
public float sqrMagnitude { [MethodImpl(MethodImplOptionsEx.AggressiveInlining)] get { return x * x + y * y; } }
huh, wonder why that uses Math and not Mathf
Because Mathf probably delegates to Math and they're trying to minimize/inline the callstack here