在IOS中将弧度转换为度

在IOS中将弧度转换为度,ios,Ios,嗨,朋友们,我需要将弧度值转换为度。下面的代码是为了得到弧度 UIView *view = [self view]; CGPoint center = CGPointMake(CGRectGetMidX([view bounds]), CGRectGetMidY([view bounds])); CGPoint currentTouchPoint = [touch locationInView:view]; CGPoint previousTouchPoint = [touch

嗨,朋友们,我需要将弧度值转换为度。下面的代码是为了得到弧度

UIView *view = [self view];
   CGPoint center = CGPointMake(CGRectGetMidX([view bounds]), CGRectGetMidY([view bounds]));
   CGPoint currentTouchPoint = [touch locationInView:view];
   CGPoint previousTouchPoint = [touch previousLocationInView:view];

   CGFloat angleInRadians = atan2f(currentTouchPoint.y - center.y, currentTouchPoint.x - center.x) - atan2f(previousTouchPoint.y - center.y, previousTouchPoint.x - center.x);
这是在触摸移动:(NSSet*)触摸事件:(UIEvent*)事件中完成的。但是我需要将这个角半径CGFloat值转换成类似45.0度的度数。我怎样才能做到这一点

我尝试了以下方法,但找不到解决方案:

  • #将弧度u定义为_度(弧度)((弧度)*(180.0/M_-PI))
  • CGFloat RadiansToDegrees(CGFloat弧度){返回弧度*180/M_PI;}
  • 试试这个:

     // Use the following macro in your code to convert radians to degrees:
    
     #define RADIANS_TO_DEGREES(radians) ((radians) * (180.0 / M_PI))
     NSLog(@"Output radians as degrees: %f", RADIANS_TO_DEGREES(0.584));
    
    否则请尝试
    (acos(0)*180)/M_PI

    注意:使用
    acosf(float)
    而不是
    acosf(double)
    (弧度)*(180.0/M_PI)
    总是给出度,计算中可能有错误尝试下面的代码可能对你有帮助


     - (double)getTheAngleBetweenPoint:(CGPoint)point1 andPoint:(CGPoint)point2
      {
        double angle;
        CGFloat delta_y = point2.y - point1.y;
        if(delta_y < 0)
        {
           delta_y *= -1;
        }
        CGFloat delta_x = point2.x  - point1.x;
        if(delta_x < 0)
        {
          delta_x *= -1;
        }
    
        angle = atan2(delta_y, delta_x) * (180/M_PI) ; //returning the tan of the angle in degree
    
       return angle;
     }
    
    
     - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
     {
         UITouch *touch = [touches anyObject];
         UIView *view = [touch view];
         double angle = [self getTheAngleBetweenPoint:[touch locationInView:view] andPoint:[touch previousLocationInView:view]];
         NSLog(@"%f",angle);
    
    }
    
    -(双精度)获取点:(CGPoint)点1和点:(CGPoint)点2之间的角度
    {
    双角度;
    CGFloat delta_y=点2.y-点1.y;
    if(δy<0)
    {
    δy*=-1;
    }
    CGFloat delta_x=点2.x-点1.x;
    if(δx<0)
    {
    delta_x*=-1;
    }
    角度=atan2(δy,δx)*(180/Mπ);//返回角度的tan(度)
    返回角;
    }
    -(无效)触摸移动:(NSSet*)触摸事件:(UIEvent*)事件
    {
    UITouch*touch=[触摸任何对象];
    UIView*视图=[触摸视图];
    双角度=[点:[触摸位置查看:视图]和点:[触摸上一个位置查看:视图]]之间的自获取角度;
    NSLog(@“%f”,角度);
    }
    


    我找到了解决办法。。在我的代码中,我只获取当前移动的角度,而不是视图的当前角度

     - (double)getTheAngleBetweenPoint:(CGPoint)point1 andPoint:(CGPoint)point2
      {
        double angle;
        CGFloat delta_y = point2.y - point1.y;
        if(delta_y < 0)
        {
           delta_y *= -1;
        }
        CGFloat delta_x = point2.x  - point1.x;
        if(delta_x < 0)
        {
          delta_x *= -1;
        }
    
        angle = atan2(delta_y, delta_x) * (180/M_PI) ; //returning the tan of the angle in degree
    
       return angle;
     }
    
    
     - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
     {
         UITouch *touch = [touches anyObject];
         UIView *view = [touch view];
         double angle = [self getTheAngleBetweenPoint:[touch locationInView:view] andPoint:[touch previousLocationInView:view]];
         NSLog(@"%f",angle);
    
    }
    
    CGFloat radians = atan2f(yourView.transform.b, yourView.transform.a); 
    CGFloat degrees = radians * (180 / M_PI);
    
    使用这个代码,我得到了我的解决方案

    感谢所有为我花费时间的人。

    #定义弧度到_度(弧度)((弧度)*(180.0/M_π))很有效,刚刚尝试过