# Finding a point within a Non Axis aligned Rectangle

Hey guys, im having a bit of trouble with some Math, i probably should have posted in the C++ section but im doing it in BPs so yeah.

Im trying to find the start point for a line trace within a box that can be scaled and rotated and all that jazz, but the Math i worked out myself just doesnt take into account the rotation of the box.

Heres what i mean.

Heres my BP nodes for calculating the starting point of the line trace, which begins at the top of the box.

To get the end of the trace i just take the box height and subtract it from the Z of its world location.

So as you can see when the box is rotated and not aligned to any axis it breaks down completely. Does anyone know the Math to get this to work?

Thanks guys.

Thanks for your help but i found my own solution elsewhere.

I needed to rotate the Vector by the actors worldrotation and then add its worldlocation.

I solved it by just getting a vector from each side of the rectangle and transforming it to rectangle local, and transforming the point in space to rectangle comp local.
Then just checking if point.X is >= rectangleXMinusSide.X && point.X <= rectangleXPlusSide.X.

Then do the same for yLeft and Right Side, and zUp and Down side.

The sides are easy to get if you have the component and its scale, here’s an example:
isVertexWithinArea_SquareXSize = rectangleComponent->GetRelativeScale3D().X * 100;

Now you can use the component location + its forward vector * isVertexWithinArea_SquareXSize / 2 to get+ side of the rectangle. Same thing for the minus side you just *-1 on the forward vector as well.

This solution supports rotated rectangles as well.