Hopefully a simple question that I am struggling with.
I am at day 115 at the start of SIMD optimisation and I am trying to work through the current DrawRectangleQuickly method to understand everything before I start with SIMD intrinsics.
I just watched the part where Casey removes the edge testing since he realised that he can just check to see if the UV coordinates are inside the square using normalised x and y axis.
However I am not too sure how he is doing this. My maths isn't as great as it should be!
I can see that Casey is calculating the normalised axis as:
| float inverseYAxisLengthSquared = 1.0f / LengthSquared(yAxis);
Vector2 nYAxis = inverseYAxisLengthSquared * yAxis;
|
Now from my understanding you normalise a vector by dividing itself with the magnitude. But that doesn't seem to be what Casey is doing here as the length is squared and not the square root?
I thought I would be able to replace the above with:
| Vector2 nYAxis = yAxis / Length(yAxis);
|
With length being Square root of the length squared. This doesn't work and seems to result always in 1.
So can someone explain to me why we divide by the squared length and not doing the square root?
Thanks.