问题
I am developing a game using COCOS2D. In my game, there are 4 points, each point is connected with each other by one line. When user moves the point, the lines move with the point. At the time of moving, if a line intersects with another line, line color should become red. How can I do this, i.e. line to colored red? And how to detect the intersection of two lines? Can anyone help me to solve this intersection problem in COCOS2D?
回答1:
You can detect whether 2 segments intersect using this function provided by cocos2d.
BOOL ccpSegmentIntersect(CGPoint A, CGPoint B, CGPoint C, CGPoint D)
回答2:
There's a question that could be considered a duplicate of your question but it's more generic:
How do you detect where two line segments intersect?
It has a few nice algorithms, though the answer that might be the most useful for you is the answer from Gavin as it provides a C function that you can easily adapt.
来源:https://stackoverflow.com/questions/8076036/intersection-between-2-lines-in-cocos2d