我得到了这个方法:
-(CGPoint) getPointOnaLine: (CGPoint) p1: (CGPoint) p2: (int) dt {
CGPoint tempPoint;
float myY = p1.y;
float len = getLineLength( p1, p2 );
float res = 1000;
// do not bother with calculation with small widths
if ( dt == 0 )
return p1;
if ( len < (2 / res ) )
return p2;
float increm = len / res;
// int min = 2;
float dY = p2.y - p1.y;
float dx = p2.x - p1.x;
if ( dx != 0 ) { // slope is infinite
float slope = dY / dx;
float b = p1.y - slope * p1.x;
if ( p1.x < p2.x ) {
for ( float i= p1.x; i<=p2.x; i=i+increm ) {
myY = (slope * i + b);
tempPoint = ccp(i,myY);
len = getLineLength( p1, tempPoint);
if ( len >= dt)
return tempPoint;
}
} else if ( p1.x > p2.x )
for ( float i= p2.x; i<=p1.x; i=i+increm) {
myY = (slope * i + b);
tempPoint = ccp(i,myY);
len = getLineLength( p2, tempPoint);
if ( len >= dt )
return tempPoint;
}
} else {
return p2;
}
return p1;
}
我在另一种方法中使用它:
CGPoint b1, b2, pt;
b1 = getPointOnaLine(originalPoint, bezierPoint, (int)t*stepLine1);
b2 = getPointOnaLine(bezierPoint, targetPoint, (int)t*stepLine2);
bLen = getLineLength(b1,b2);
stepLine3 = bLen / frames;
pt = getPointOnaLine(b1,b2,(int)self.tCGPoint b1, b2, pt;
编译器一直告诉我“赋值中的类型不兼容”,我在其中声明了 b1、b2 和 pt。界面是:
-(CGPoint) getPointOnaLine: (CGPoint) p1: (CGPoint) pt2: (int) dt;
如果我删除分配,它只会给我一个隐式声明警告。我真的很困惑为什么这不会编译。
克里斯