OGeek|极客世界-中国程序员成长平台

标题: ios - 使用Objective c在弧上点 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 15:09
标题: ios - 使用Objective c在弧上点

我在获取圆弧上的点时遇到问题。我画了一条弧线。我想使用半径、原点和角度来获得圆弧上的点。在我的情况下,起源是 150,150。半径为 50。起始角度为 0,结束角度为 180。当我试图在角度 M_PI/2 处获取点时,它应该在弧的中间对齐,但它给出了错误的 x 和 y 值。如果我遗漏任何东西,请告诉我。

enter image description here

我的代码是

 - (void)drawRectCGRect)rect
{
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetLineWidth(context, 4.0);
    CGContextSetStrokeColorWithColor(context,
                                     [UIColor blueColor].CGColor);
    CGContextAddArc(context, 150, 150, 50, 0, M_PI, 0);
    CGContextStrokePath(context);

}

-(CGPoint)getPointfloat)angle
{
    float radius = 50;
    //float x = 160+radius*cos(-M_PI/2);
    //float y = 160+radius*sin(-M_PI/2);

    float x = 150+radius*cos(angle);
    float y = 150+radius*sin(angle);

    return CGPointMake(x, y);
}



Best Answer-推荐答案


如果你得到一个点 (177, 192),就像你在评论中写的那样,这意味着你通过的角度大约等于 1。这不是 M_PI/2,大约是 1.57

所以,问题在于您传递的值,而不是提到的函数。也许你错误地将角度四舍五入为整数?

关于ios - 使用Objective c在弧上点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30076953/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4