What's the algorithm for determining whether or not a point is inside of a rectangle? (have a point (x,y) and all the points on the rectangle...) Thanks!
If your point is say (3,4) and your rectangle corners are say (1,2),(1,5),(4,2) and (4,5) then your rectangles x range is between 1 and 4 and the y range is between 2 and 5. Thus, you simply have to check if the point's x is within the rectangle's x range AND the point's y is within the rectangle's y range. In this example the point's x is 3 which is between 1 and 4. The point's y is 4 which is between 2 and 5. Since both are true then the point is within the rectangle. Or in some code like format if (rectangle.lowx <= point.x <= rectangle.highx) and (rectangle.lowy <= point.y <= rectangle.highy) then print "I am inside the rectangle!" Exact coding of course depends on language.
Thank you!
Join our real-time social learning platform and learn together with your friends!