- Home /

# Squared vector divided by squared magnitude

That's almost certainly a laughably simple math question, but I don't have the vocabulary to Google it.

My understanding is that `.normalized`

basically divides a vector by its magnitude, in turn obtained with a costly square root calculation. The page on `.sqrMagnitude`

recommends avoiding the calculation altogether when possible, by using `.sqrmagnitude`

with the square of whatever you're comparing your magnitude with.

I was wondering if that method applies to vectors. Will I get a normalised vector by squaring it, then dividing it by its squared magnitude? Does `.normalized`

already do that?

Vector3.normalized exactly does that. Calculates the square root to get the magnitude and then divide.

Anyway, you sould not worry much between Vector3.sqrMagnitude or Vector3.magnitude. Using .sqrMagnitude or .normalized will only make a difference if you call them many many times every update.

Its components, I mean. As in

```
v = new Vector3 (v.x * v.x, v.y * v.y, v.z * v.z);
```

Or

```
v = Vector3.Scale (v, v);
```

Then, to be frank, you should say so (ie edit the question) rather than talking about "squaring a vector". Making up your own names for algebraic operations is not going to help you to get help!

But anyway, I'm afraid you're on a wild goose chase here. The "magnitude comparison" operation can be done without ever computing the magnitude, because you don't actually care what it *is*, all you care about it how it compares to some other value.

Normalisation is different. A normalised vector *is* the vector divided by its magnitude. Hence, you need the actual magnitude.

**Answer** by wibble82
·
Dec 15, 2015 at 11:04 AM

Hey

The basic answer to the question:

I was wondering if that method applies to vectors. Will I get a normalised vector by squaring it, then dividing it by its squared magnitude? Does .normalized already do that?

Is no, you can't :)

The vector, v = new Vector3 (v.x * v.x, v.y * v.y, v.z * v.z) has no strong mathematical meaning - that's not how you multiply vectors together.

There are 2 ways to multiply vectors together:

The DOT PRODUCT, sometimes called an inner product, which gives a

*scalar*(1 float) result. Vector3.Dot(a,b) = a.x*b.x + a.y*b.y + a.z*b.z. The squared magnitude of a vector is actually got by doing the dot product of a vector with itself. i.e. a.sqrMagnitude = a.x*a.x+a.y*a.y+a.z*a.zThe OUTER PRODUCT gives a 3x3 matrix, and is a more complex mathematical concept which I won't go into here, cos it's not too useful until you want to work out tensors or eigenvalues and stuff! :)

So:

a.sqrMagnitude = Vector3.Dot(a,a) = a.x*a.x+a.y*a.y+a.z*a.z

and

a.magntidue = Mathf.Sqrt(a.sqrMagnitude) = Mathf.Sqrt(a.x*a.x+a.y*a.y+a.z*a.z)

When people talk about avoiding the use of 'magnitude', they generally mean that if all you want to know is "is my vector less than / more than a given length", then you can do it more efficiently by looking at sqrMagnitude:

```
float maxlen = 10.0f;
if(a.magnitude < maxlen)
{
//something here
}
```

is exactly the same as

```
float maxlen = 10.0f;
if(a.sqrMagnitude < maxlen*maxlen)
{
//something here
}
```

Hope that clarifies it a bit :)

Ugh, I was hoping to never see the word eigenvalue ever again, thanks! ;) Great post though. Just don't mention vector spaces, and we'll be fine. hehe

**Answer** by Soraphis
·
Dec 14, 2015 at 12:14 PM

Vector(2, 0) -> normalized = Vector(1, 0)

```
Vector(a, b) -> SqrMagnitude = a*a + b*b (pythagoras)
Vector(a, b) -> Magnitude = Sqrt(a*a + b*b)
Vector(a, b) -> normalized = 1/Sqrt(a*a + b*b) * Vector(a, b) = Vector(a / Sqrt(a*a + b*b), b / Sqrt(a*a + b*b) )
```

if you want to check if a vectors length is ... say less then 10:

```
if( v.Magnitude < 10)
```

is the same as:

```
if( v.SqrMagnitude < 100)
```

So, can I weasel out of the sqrt call by squaring the vector's components, then divide *that* by its original squared magnitude?

No, you can't. You can easily see this by considering a vector such as (1,2).

Squaring both elements gives you (1,4) which is a different direction to (1,2), and dividing a vector by a scalar does not change its direction. Since all you're proposing doing with these 2 vectors is dividing each of them by a scalar, there's no way that that can result in identical vectors.

Just an extra note, unrelated to the question: the Vector.normalized property computes a temporary value and returns it while the Vector.Normalize() method modifies the vector, and returns the normalized value. So use Normalize() if you need to call .normalized more than once (or assign Vector.normalized to a new variable and use it).

### Your answer

### Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.

### Follow this Question

### Related Questions

force.normalized * magnitude 1 Answer

Vector3 values always precalculated, or just in MonoDevelop? 1 Answer

Jumping problem to do with /= magnitude changing the vector3 direction 1 Answer

Return grid points within a cube selection 1 Answer

Calculate Bullet based on enemy speed and distance from player 0 Answers