【发布时间】:2014-02-24 18:52:31
【问题描述】:
我已经用谷歌搜索了一段时间,但我似乎没有找到一个好的答案。我只找到了一个关于路径交集的模板,但它有点太复杂了,并不是我想要的,因为我只需要一个返回 YES 或 NO 的 BOOL 的函数。
//This is my code so far. Its getting called every time the touch is moved.
UIGraphicsBeginImageContext(CGSizeMake(320, 568));
[drawImage.image drawInRect:CGRectMake(0, 0, 320, 568)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 8.0);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 0, 1, 0, 1);
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), greentmporary.x, greentmporary.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), greenpoint1.x, greenpoint1.y);
CGContextStrokePath(UIGraphicsGetCurrentContext());
[drawImage setFrame:CGRectMake(0, 0, 320, 568)];
drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[self.view addSubview:drawImage];
【问题讨论】:
-
问题是什么?
-
如何确定两条线的 cgcontextintersection。对不起,我应该更清楚
-
一些数学怎么样? Line-line intersection (Wikipedia)
-
我认为在这种情况下,仅使用基本数学很难确定。我需要类似this
-
这一切都归结为(或多或少)基础数学;)
标签: iphone objective-c xcode cgcontext cgpath