2013-11-23 21 views
1

我需要从我的基底UIView的中心点获得指定角度和距离(半径)的特定点。我发现这个问题How to calculate a point with an given center, angle and radius?,但这并没有给我正确的观点。我使用下面的代码来找到点,从角度和半径获取x,y点

基本上我需要从我的基本视图中心点的100px距离和90度(时钟方向)找到x,y点。

int angle = 90 * M_PI/180;//need to find the point of 90 degrees 
int distance = 100; 
int line_end_x = 160 + cos(angle)*distance;//160 is my center x 
int line_end_y = 274 + sin(angle)*distance;//274 is my center y 
myView.center = CGPointMake(line_end_x, line_end_y); 

上面的代码给我下面的输出,

红盒子 “MyView的” 与(20像素X 20像素)

enter image description here

可能有人能告诉我什么是错我是在做什么?

回答

4

我怀疑你希望你的角度被表示为int。 你的角度是Pi/2,它是1.57。

也许尝试float angle = 90 * M_PI/180;

+0

哦~~谢谢你,伙计,我是这么不见了... –

+0

如果有人好奇地想知道,0度,从3开始在钟盘,误我从12我的形象开始。 –

+1

是的,惯例是角度的起源是'x'轴,* ie *。水平的;-) – Olotiar