菜鸟教程小白 发表于 2022-12-11 20:17:52

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


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

<p>现在我正在绘制一个带有该点的矩形。宽度为 100,高度为 10。角度为 0。<br/>见屏幕截图 <br/>
<img src="/image/11NTM.png" alt="enter image description here"/> </p>

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

<p>对于矩形的角度是 90。<br/>这个点矩形没有正确绘制<br/>看屏幕截图<br/>
<img src="/image/ZfSo5.png" alt="enter image description here"/> </p>

<p>我绘制矩形的代码是:<br/></p>

<pre><code>    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);
</code></pre>

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

<p>更多引用 <a href="https://stackoverflow.com/questions/644378/drawing-a-rotated-rectangle" rel="noreferrer noopener nofollow">see this</a> </p>

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

<p>谢谢,</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>让我猜猜,它实际上旋转了大约 26 度,对吧?</p>

<p>(<strong>90</strong> x 180)/Pi ~= 5156.62 = (360 x 14) + <strong>90</strong> + <strong>26.62</strong></p>

<p>您错误地将其旋转了 90 个<strong>弧度</strong>。</p></p>
                                   
                                                <p style="font-size: 20px;">关于iphone - 对象旋转不正确 - iPhone 应用程序,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/7610672/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/7610672/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: iphone - 对象旋转不正确 - iPhone 应用程序