/** * 根据圆心的坐标点、半径、当前手势所在的坐标点,计算出圆的运动轨迹坐标 * @param radius 圆心半径 * @param centerCircle 圆心的坐标点 * @param currentPoint 当前的手势所在的坐标点 * @return CGPoint 返回圆的坐标 */ +(CGPoint)CirclePoint:(CGFloat)radius withCenterCircle:(CGPoint)centerCircle withCurrentPoint:(CGPoint)currentPoint; +(CGPoint)CirclePoint:(CGFloat)radius withCenterCircle:(CGPoint)centerCircle withCurrentPoint:(CGPoint)currentPoint { CGPoint cPoint; CGFloat x = currentPoint.x; CGFloat y = currentPoint.y; CGFloat cX ; //圆的X坐标轨迹 CGFloat cY ; //圆的Y坐标轨迹 CGFloat daX; // 圆心到转动按钮的距离的平方 //CGFloat daY; CGFloat aX; // 圆心到转动按钮的距离 //CGFloat aY; CGFloat cosX; // 圆心水平方向与转动按钮形成的夹角的cos值 //圆心与触控点的距离的平方(勾股定理) daX = (x - centerCircle.x)*(x - centerCircle.x) + (y - centerCircle.y)*(y - centerCircle.y); aX = sqrt(daX); //开根号 //圆心与触控点的距离 cosX = fabs(x - centerCircle.x)/aX; //绝对值 cX = cosX*radius ; // x =R * cosX; 圆心到触控点在水平坐标的X的值 cY = sqrt(radius*radius - cX*cX); if(x<centerCircle.x) //如果X所在的点小于圆心 在圆心的左边 { cX = centerCircle.x - cX; } else { cX = centerCircle.x + cX; } if(y<centerCircle.y) { cY = centerCircle.y - cY; } else { cY = centerCircle.y + cY; } cPoint.x = cX; cPoint.y = cY; return cPoint; }