Ios 如何找到曲线和直线的交点?
我画的是11点的曲线和直线。是否可以检测出两条直线(或两条曲线)的交点(或一条直线和一条曲线) 我正在使用Ios 如何找到曲线和直线的交点?,ios,objective-c,cgcontext,Ios,Objective C,Cgcontext,我画的是11点的曲线和直线。是否可以检测出两条直线(或两条曲线)的交点(或一条直线和一条曲线) 我正在使用 CGMutablePathRef path = CGPathCreateMutable(); for (int i = 0; i < [_points count]; i++) { CGPoint pt = [[_points objectAtIndex:i] CGPointValue]; if (i == 0) { CGPathMoveTo
CGMutablePathRef path = CGPathCreateMutable();
for (int i = 0; i < [_points count]; i++)
{
CGPoint pt = [[_points objectAtIndex:i] CGPointValue];
if (i == 0)
{
CGPathMoveToPoint(path, NULL, pt.x+1, pt.y+1);
}
else
{
CGPathAddLineToPoint(path, NULL, pt.x+1, pt.y+1);
}
}
CGContextSetLineWidth(context, 1.0f);
CGContextSetStrokeColorWithColor(context, curveColor.CGColor);
CGContextAddPath(context, path);
CGContextStrokePath(context);
CGPathRelease(path);
CGMutablePathRef path=CGPathCreateMutable();
对于(int i=0;i<[u点数];i++)
{
CGPoint pt=[[u points objectAtIndex:i]CGPointValue];
如果(i==0)
{
CGPathMoveToPoint(路径,NULL,pt.x+1,pt.y+1);
}
其他的
{
CGPathAddLineToPoint(路径,NULL,pt.x+1,pt.y+1);
}
}
CGContextSetLineWidth(上下文,1.0f);
CGContextSetStrokeColorWithColor(上下文,curveColor.CGColor);
CGContextAddPath(上下文,路径);
CGContextStrokePath(上下文);
CGPathRelease(路径);
曲线绘制
CGMutablePathRef path = CGPathCreateMutable();
for (int i = 0; i < [_points count]; i++)
{
CGPoint pt = [[_points objectAtIndex:i] CGPointValue];
NSLog(@"%@",NSStringFromCGPoint(pt));
if (i == 0)
{
CGPathMoveToPoint(path, NULL, pt.x, pt.y);
}
else
{
CGPoint curP = [[_points objectAtIndex:i-1] CGPointValue];
float delta = 1.0f;
for (float pointX = curP.x; fabs(pointX - pt.x) > 1e-5f; pointX += delta)
{
float pointY = func(i-1, pointX);
CGPathAddLineToPoint(path, NULL, pointX, pointY);
}
}
CGContextSetLineWidth(context, 1.0f);
CGContextSetStrokeColorWithColor(context, curveColor.CGColor);
CGContextAddPath(context, path);
CGContextStrokePath(context);
CGPathRelease(path);
CGMutablePathRef path=CGPathCreateMutable();
对于(int i=0;i<[u点数];i++)
{
CGPoint pt=[[u points objectAtIndex:i]CGPointValue];
NSLog(@“%@”,NSStringFromCGPoint(pt));
如果(i==0)
{
CGPathMoveToPoint(路径,NULL,pt.x,pt.y);
}
其他的
{
CGPoint curP=[[u points objectAtIndex:i-1]CGPointValue];
浮动增量=1.0f;
对于(浮点x=curP.x;晶圆厂(pointX-pt.x)>1e-5f;pointX+=delta)
{
浮点y=func(i-1,点x);
CGPathAddLineToPoint(路径,空,点x,点y);
}
}
CGContextSetLineWidth(上下文,1.0f);
CGContextSetStrokeColorWithColor(上下文,curveColor.CGColor);
CGContextAddPath(上下文,路径);
CGContextStrokePath(上下文);
CGPathRelease(路径);
使用这些代码如何找到交点。- 要查找两条直线的交点,请参见
- 要使一条线和一条曲线相交-你的曲线只是一组线,因此如果该线与集合中的任何一条线相交,则该线与该组线相交
- 要使曲线和曲线相交,请将一条曲线中的每条线与另一条曲线中的每条线进行检查
优化的方法有很多种,比如首先碰撞曲线或直线的边界矩形。我想你知道你必须在目标c中自己做的数学,没什么大不了的,为它做一个函数你的第一个点链接给出真/假条件。为此,我有很多方法。但问题是我想要交点第二点和第三点,我不知道怎么做。就是这样,我把问题贴在这里了。Thanks@Hack_123:好的,我在谷歌上搜索了一下,找到了一个objective-c答案,给出了交点。链接更新。对于2和3,你使用了一个For循环。从字面上说,假设你有一条X线,其中有a、B、c、D和E线的曲线。你应用了fr算法om#1在X和A之间。如果是命中,那就是你的答案。如果不是,你把它应用到X和B上。如果是命中,那就是你的答案。如果不是,试试C,等等。如果没有匹配,那就没有交集。谢谢你的重播…直线交集有效…曲线和直线曲线我会检查并让你知道。。