简体   繁体   中英

Find collision between 2 polygons

It's problem from the book:

"Computational Geometry: Algorithms and Applications", Springer-Verlag.

Given two simple and disjoint polygons P and Q, where P lies strictly to the left of Q, computes the first points on the polygons that will collide if P is translated horizontally and in the positive x-direction, or determines that they do not collide.

在此处输入图片说明

I have a quadratic solution, but it should be O((n+m) log(n+m))

Probably not the answer you are looking for, but the simple, quick and easy to develop solution would be to draw the polygons, fill them and do bitwise masking AND function to determine the bits that overlap on a bitmap.

Looping with increments of 1 bit on the x-scale and performing the AND masking test each iteration gives you the perfect contact point in exact pixels.

pixel perfect collision detection

Sort both polygons top to bottom and implement a sweepline process. The vertices are the event points. While sweeping, keep a trace of the rightmost edge of P and the leftmost edge of Q. You can draw horizontal segments in between, and keep the shortest of all.

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM