gpt4 book ai didi

iphone - 对象旋转不正确 - iPhone 应用程序

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:25:31 25 4
gpt4 key购买 nike

我在旋转物体时遇到了一个典型的问题。说明如下
我拿了两个 CGPoint 让我们说 point1 和 point2
point1 = (50,50)
point2 = (150, 50)
此点将绘制一条水平线。

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

工作正常
现在我换个说法
point1 = (50,50)
point2 = (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

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

谢谢,

最佳答案

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

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

你错误地将它旋转了 90 弧度

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com