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

标题: iphone - 对象旋转不正确 - iPhone 应用程序 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 20:17
标题: iphone - 对象旋转不正确 - iPhone 应用程序

我在旋转对象时遇到了一个典型问题。描述如下
我拿了两个 CGPoint,比如说 point1 和 point2
点1 = (50,50)
点2 = (150, 50)
这个点会画一条水平线。

现在我正在绘制一个带有该点的矩形。宽度为 100,高度为 10。角度为 0。
见屏幕截图
enter image description here

工作正常
现在我换个角度来说说
点1 = (50,50)
点2 = (50,150)
这个点会画一条垂直线。

对于矩形的角度是 90。
这个点矩形没有正确绘制
看屏幕截图
enter image description here

我绘制矩形的代码是:

    CGPoint mid = CGPointMake((point1.x+point2.x)/2, (point1.y+point2.y)/2)
    CGPoint UL = CGPointMake(mid.x + ( Width / 2 ) * cos (A) - ( Height / 2 ) * sin (A) ,  mid.y + ( Height / 2 ) * cos (A)  + ( Width / 2 ) * sin (A));
    CGContextMoveToPoint(context, UL.x,routeView.frame.size.height - UL.y);
    CGPoint UR = CGPointMake(mid.x - ( Width / 2 ) * cos (A) - ( Height / 2 ) * sin (A) ,  mid.y + ( Height / 2 ) * cos (A)  - ( Width / 2 ) * sin (A));
    CGContextAddLineToPoint(context, UR.x,routeView.frame.size.height - UR.y);
    CGPoint BR = CGPointMake(mid.x - ( Width / 2 ) * cos (A) + ( Height / 2 ) * sin (A) ,  mid.y - ( Height / 2 ) * cos (A)  - ( Width / 2 ) * sin (A));
    CGContextAddLineToPoint(context, BR.x,routeView.frame.size.height - BR.y);
    CGPoint BL = CGPointMake(mid.x + ( Width / 2 ) * cos (A) + ( Height / 2 ) * sin (A) ,  mid.y - ( Height / 2 ) * cos (A)  + ( Width / 2 ) * sin (A));
    CGContextAddLineToPoint(context, BL.x,routeView.frame.size.height - BL.y);
    CGContextAddLineToPoint(context, UL.x,routeView.frame.size.height - UL.y);

    CGContextStrokePath(context);

这里A是Angle,不是静态的,mid是point1和point2的中点

更多引用 see this

我错过了什么吗? 如果您有任何想法,请帮助我.......

谢谢,



Best Answer-推荐答案


让我猜猜,它实际上旋转了大约 26 度,对吧?

(90 x 180)/Pi ~= 5156.62 = (360 x 14) + 90 + 26.62

您错误地将其旋转了 90 个弧度

关于iphone - 对象旋转不正确 - iPhone 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7610672/






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