Reinventing The (Square) Wheel Department. Problem: given a rectangle ABCD defined by four points on the xy-plane, detect whether a given point (a mouseclick) falls inside ABCD. Note that side AB isn't necessarily parallel to the x or y axes.
Currently I'm using a cumbersome algorithm based on deciding which side of a straight line the given point lies. The only thing in its favor is that it generalizes to handle an irregular convex polygon. But that's not needed here. It would be nice to transform the rectangle to situate A at the origin, then apply a simple range check on x and y. In practice it would only be the mouseclick that got transformed (by the inverse matrix). I can't believe someone hasn't already got a slick verb to do it. Games programmers must do it all the time! It would be nice too to see a solution using complex numbers instead of 2-by-2 matrices. I read somewhere that complex numbers were actually developed before matrix theory, allegedly to handle coordinate geometry on the 2-plane. Can anyone verify or refute this? Displacement in the xy-plane can't normally be represented by a linear transformation, but long ago I read of a way of introducing a third virtual z-axis, which did allow both rotation and displacement to be handled in one shot by a 3-by-3 matrix. Does anybody know of this technique? ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
