I have four points in 2D space that make up a rectangle, top left, top right, bottom left and bottom right. Given the x and y of an arbitrary point I want to know where that lies in the rectangle. eg, if the point happens to lie on the top left corner it'd be (0,0) and if it happens to lie an the bottom right corner it'd be (width,height). I don't have a rotation matrix for said rectangle but I could make one from the points. I just thought there should be a much simpler way but my mind is having a blank.

I guess it'll be better if you just make the translation and rotation of the rectangle and the point, and then a simple substraction will give you the result.

If you really want to avoid that you can define two lines in space, one from top-left to top-right and the other from top-left to bottom left. Then, compute the distance of the arbitrary point to each of those lines. Those distances will be the result you want: http://en.wikipedia.org/wiki/Distance_from_a_point_to_a_line

Anyway, the second method looks more complex than the first one with those squared roots and power of 2, and the need of compute the lines of the rectangle.

Hmm. Actually, it could be a trapezoid based on the position of the camera.

What are you trying to do? Is it a 2D or 3D game? If the camera position makes a rectangle look like a trapezoid then I guess it's 3D, in which case translation and rotation matrices will make everything easier for future stuffs.

**Edited by DiegoSLTS, 20 June 2014 - 09:12 AM.**