美文网首页
根据两点计算延伸点

根据两点计算延伸点

作者: Leon1024 | 来源:发表于2019-01-01 21:02 被阅读0次
    // 从两个点计算出指定延伸长度外的射线点,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);
    }
    
    

    相关文章

      网友评论

          本文标题:根据两点计算延伸点

          本文链接:https://www.haomeiwen.com/subject/tvsolqtx.html