#To get the actual magnitude

1 messages · Page 1 of 1 (latest)

hardy pollen
#

but then why to used .magnitude ?

cyan axle
#

For convenience

hardy pollen
#

im not getting core difference of it

thorny flower
#

magnitude is sqrt(sqrMagnitude), yes

#

but magnitude is used for a lot of things

hardy pollen
#

i know pythagoras theorem and all in maths but not getting this

thorny flower
#

it'd be inconvenient to write the sqrt every time

cyan axle
#

There's no difference between taking .sqrMagnitude and calling sqrt yourself vs just .magnitude

thorny flower
#

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

hardy pollen
#

ahhhhhhhhhhhh im not getting this bro😭

cyan axle
#

I'm confused about what you're confused about now tbh

hardy pollen
#

i need a video tutorial of this i guess

cyan axle
hardy pollen
thorny flower
#

there isn't one

#

you're trying to look for differences that don't exist here mate

hardy pollen
cyan axle
#

sqrMagnitude is Pythagorean theorem without the sqrt over everything.

Magnitude is with the sqrt

#

That's it

thorny flower
#

the only difference is one is squared

cyan axle
#

Or rather, not square rooted

cyan axle
#

Yes

thorny flower
#

that's what we've been saying the entire time

hardy pollen
#

but can you explain what will be difference between them?

thorny flower
#

one is squared

hardy pollen
#

nooo i mean in their calculated values

thorny flower
#

yes, one will be squared

cyan axle
#

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.

thorny flower
#

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; } }
thorny flower
cyan axle
#

Because Mathf probably delegates to Math and they're trying to minimize/inline the callstack here