Article Preview
Buy Now
| Print: | |
| PDF: |
Feature
Polygon Hit Testing
Is a point inside a polygon?
Issue: 3.4 (March/April 2005)
Author: Thomas Reed
Author Bio: Thomas Reed has been programming as a hobbyist for more than 20 years, and fell in love with the Mac in 1984.
Article Description: No description available.
Article Length (in bytes): 7,050
Starting Page Number: 34
RBD Number: 3415
Resource File(s):
3415.sit Updated: Tuesday, March 15, 2005 at 7:49 PM
3415.zip Updated: Tuesday, March 15, 2005 at 7:49 PM
Related Link(s): None
Known Limitations: None
Excerpt of article text...
Hit testing -- that is, determining whether a point lies within an object -- is a recurring problem in many programs. Applications of hit testing can range from collision testing in games to deciding whether a mouse click lies within a user interface element. Such decisions are trivial for rectangular objects, and only slightly more complex for ovals, rounded rectangles, triangles, and other such regular shapes.
However, when it comes to determining whether a point lies inside an arbitrary, irregular shape, many people throw up their hands. While this is often a trivial determination for a human, who comes equipped with very complex visual computing hardware, telling a computer how to come to the same conclusion seems difficult. How is it done?
One oft-used solution involves storing an off screen bitmap image of the shape, in which black pixels lie inside the shape and white pixels lie outside. Hit-testing becomes as simple as checking the color of the pixel at the given point. However, this method can easily become impractical. For example, the shape may be defined at runtime, thus requiring that you figure out what pixels lie inside it anyway, in order to generate the pixel map. It seems that there must be another way.
...End of Excerpt. Please purchase the magazine to read the full article.
Article copyrighted by REALbasic Developer magazine. All rights reserved.
|







