#import "BNZLine.h" void DoLineSegmentIntersection(BNZVector *v1, BNZVector *v2, BNZVector *v3, BNZVector *v4) { BNZLine *l1 = [BNZLine lineAt:v1 to:v2]; BNZLine *l2 = [BNZLine lineAt:v3 to:v4]; BNZVector *intersection; NSLog(@"Line segment 0: %@", l1); NSLog(@"Line segment 1: %@", l2); switch([l1 getIntersectionPoint:&intersection withLine:l2]) { case BNZLinesAreParallel: NSLog(@"The lines are parallel\n"); break; case BNZLinesAreCoincident: NSLog(@"The lines are coincident\n"); break; case BNZLinesDoNotIntersect: NSLog(@"The lines do not intersect\n"); break; case BNZLinesIntersect: NSLog(@"The lines intersect at %@", intersection); break; } } int main() { NSAutoreleasePool *p = [[NSAutoreleasePool alloc] init]; DoLineSegmentIntersection(VecXY(0.0f, 0.0f), VecXY(5.0f, 5.0f), VecXY(5.0f, 0.0f), VecXY(0.0f, 5.0f)); DoLineSegmentIntersection(VecXY(1.0f, 3.0f), VecXY(9.0f, 3.0f), VecXY(0.0f, 1.0f), VecXY(2.0f, 1.0f)); DoLineSegmentIntersection(VecXY(1.0f, 5.0f), VecXY(6.0f, 8.0f), VecXY(0.5f, 3.0f), VecXY(6.0f, 4.0f)); DoLineSegmentIntersection(VecXY(1.0f, 1.0f), VecXY(3.0f, 8.0f), VecXY(0.5f, 2.0f), VecXY(4.0f, 7.0f)); DoLineSegmentIntersection(VecXY(1.0f, 2.0f), VecXY(3.0f, 6.0f), VecXY(2.0f, 4.0f), VecXY(4.0f, 8.0f)); DoLineSegmentIntersection(VecXY(3.5f, 9.0f), VecXY(3.5f, 0.5f), VecXY(3.0f, 1.0f), VecXY(9.0f, 1.0f)); DoLineSegmentIntersection(VecXY(2.0f, 3.0f), VecXY(7.0f, 9.0f), VecXY(1.0f, 2.0f), VecXY(5.0f, 7.0f)); [p release]; return 0; }