作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
因为我数学很烂,this paper on the topic一个字都听不懂, 和 this answer I found对我来说解释得不够清楚,有人可以用伪代码向我展示用于旋转线段的算法,比如在 (50,40) - (50,120) 处围绕其中心点(90 度)绘制的图表?非常感谢。
最佳答案
90 度是一个简单的特例。假设您有一条从 (x1,y1)
到 (x2,y2)
的行:
//find the center
cx = (x1+x2)/2;
cy = (y1+y2)/2;
//move the line to center on the origin
x1-=cx; y1-=cy;
x2-=cx; y2-=cy;
//rotate both points
xtemp = x1; ytemp = y1;
x1=-ytemp; y1=xtemp;
xtemp = x2; ytemp = y2;
x2=-ytemp; y2=xtemp;
//move the center point back to where it was
x1+=cx; y1+=cy;
x2+=cx; y2+=cy;
关于algorithm - 如何将线段绕其中心旋转 90 度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45701615/
我是一名优秀的程序员,十分优秀!