【问题标题】:object rotation is not proper - iPhone application对象旋转不正确 - iPhone 应用程序
【发布时间】:2011-09-30 12:55:34
【问题描述】:

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

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

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

矩形角度为 90。
使用此点矩形绘制不正确
请参见屏幕截图

我绘制矩形的代码是:

    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

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

谢谢,

【问题讨论】:

  • a 是角度,第一种情况为 0,第二种情况为 90

标签: iphone ios math rotation cgcontext


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 2012-03-25
    • 1970-01-01
    • 2017-11-20
    • 1970-01-01
    • 1970-01-01
    • 2012-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多