Handmade Hero»Forums»Code
Jay
18 posts
Finding UV coordinates - questions regarding axis
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:

1
2
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:

1
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.
6 posts
None
Finding UV coordinates - questions regarding axis
Hello Jay,

Casey explains this on Day 93 - Textured Quadrilaterals - around 15:50.

Best,
Jimmy
Jay
18 posts
Finding UV coordinates - questions regarding axis
Ah I obviously wasn't paying enough attention during that stream! Thanks Jimbo!