Created
September 12, 2014 02:49
-
-
Save qingjoin/13828155310363e1df25 to your computer and use it in GitHub Desktop.
iOS 计算圆的运动轨迹坐标
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// CircleXYZ.m | |
// Metronome | |
// | |
// Created by qingyun on 9/11/14. | |
// Copyright (c) 2014 qingyun. All rights reserved. | |
// | |
#import "CircleXYZ.h" | |
@implementation CircleXYZ | |
/** | |
* 根据圆心的坐标点、半径、当前手势所在的坐标点,计算出圆的运动轨迹坐标 | |
* @param radius 圆心半径 | |
* @param centerCircle 圆心的坐标点 | |
* @param currentPoint 当前的手势所在的坐标点 | |
* @return CGPoint 返回圆的坐标 | |
*/ | |
+(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; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment