How to intersect two polygons?

Arash Partow’s FastGEO library contains implementations of many interesting algorithms in computational geometry. Polygon intersection is one of them. It’s written in Pascal, but it’s only implementing math so it’s pretty readable. Note that you will certainly need to preprocess your edges a little, to get them into clockwise or counterclockwise order. ETA: But really, … Read more

3D Line-Plane Intersection

Here is a Python example which finds the intersection of a line and a plane. Where the plane can be either a point and a normal, or a 4d vector (normal form), In the examples below (code for both is provided). Also note that this function calculates a value representing where the point is on … Read more

Finding Intersection of NSMutableArrays

Use NSMutableSet: NSMutableSet *intersection = [NSMutableSet setWithArray:array1]; [intersection intersectSet:[NSSet setWithArray:array2]]; [intersection intersectSet:[NSSet setWithArray:array3]]; NSArray *array4 = [intersection allObjects]; The only issue with this is that you lose ordering of elements, but I think (in this case) that that’s OK. As has been pointed out in the comments (thanks, Q80!), iOS 5 and OS X 10.7 … Read more

Efficient maths algorithm to calculate intersections

Most of the answers already here seem to follow the general idea that: find the intersection of two straight lines passing the given points. determine if the intersection belong to both line segments. But when intersection does not occur often, a better way probably is to reverse these steps: express the straight lines in the … Read more