Special

Clearance Sale!

We've been publishing for over five years now and it's time to clear out our inventory of back issues, so we're slashing prices!

RBD Magazines

Check out this amazing clearance sale of all our past issues. Missing some issues? This is a great time to complete your RBD collection. Save up to 40% off the regular price of our printed back issue packages. These prices are only good until the end of the year May 2008 and supplies are limited, so place your order today.

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):

Download Icon 3415.sit Updated: Tuesday, March 15, 2005 at 7:49 PM
Download Icon 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.


 


|

 


Weblog Commenting and Trackback by HaloScan.com