// 从两个点计算出指定延伸长度外的射线点,isNextPoint为YES则为向前点,否则为当前点的向后点
- (CGPoint)pointWithExtendLength:(CGFloat)length lastPoint:(CGPoint)pointA currentPoint:(CGPoint)pointB isNextPoint:(BOOL)isNext {
CGFloat relativeX = pointB.x - pointA.x;
CGFloat relativeY = pointB.y - pointA.y;
CGFloat relativeZ = hypot(relativeX, relativeY); // 直角三角形求斜边
CGFloat x = relativeX / relativeZ * length;
CGFloat y = relativeY / relativeZ * length;
if (isNext) {
return CGPointMake(pointB.x + x, pointB.y + y);
}
return CGPointMake(pointB.x - x, pointB.y - y);
}
网友评论