Q:
what if the rectangle is rotated?
Given 4 points of the rectangle.
and a target point.
A:
1: for each parrallel lines of the rectangle, we apply the point to these lines, and see their signs. if + and - , then within range.
similarly for another pair.
2: ( From leetcode)
we can utilize dot product. The trick is to use dot product to find the
projected line from point P onto the rectangle sides, and if its length
is shorter than the sides, then the point must be inside the rectangle.
No comments:
Post a Comment