多边形围绕中心旋转 [英] Polygon rotation around center
本文介绍了多边形围绕中心旋转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
hi
我有一个制作多边形的点数组。如何围绕其中心旋转多边形。
我尝试过:
公共函数RotatePoints(_Points()As Point,_ CenterPoint As Point,_Degree As Double)As Point()
Dim Output()As Point = _Points.Clone()
Dim Angle As Double =(_ Decree / 180.0)* Math.PI
索引为整数= 0到Output.Length - 1
输出(索引)=新点(数学。 Cos(角度)*(输出(索引).X - _CenterPoint.X))+ _ CenterPoint.X,(Math.Sin(角度)*(输出(索引).Y - _CenterPoint.Y))+ _ CenterPoint.Y)
下一个
返回输出
结束函数
解决方案
简单:你的算法错了。
见这里:几何操作 - 旋转 [ ^ ]
我建议你你将每个坐标分解成一组单独的行,让X工作 - 显然,使用调试器检查 - 然后重复Y.当两者都工作时,将X和Y的各个阶段合并成单行并创建你的新观点。
特别感谢OriginalGriff
公共函数RotatePoints2(_Points()As Point ,_CenterPoint As Point,_Degree As Double)As Point()
Dim Output()As Point = _Points.Clone()
Dim Angle As Double =(_ Decree / 180.0)* Math。 PI
对于Index As Integer = 0 To Output.Length - 1
Dim Dx As Integer =(输出(索引).X - _CenterPoint.X)
Dim Dy As Integer =(输出(索引).Y - _CenterPoint.Y)
输出(索引).X =(Math.Cos(角度)* Dx) - (Math.Sin(角度)* Dy)+ _CenterPoint.X
输出(索引).Y =(Math.Sin(角度)* Dx)+(Math.Cos(角度)* Dy)+ _CenterPoint.Y
下一个
返回输出
结束函数
hi
I have an array of points that makes a polygon. how can i rotate polygon around its center.
What I have tried:
Public Function RotatePoints(_Points() As Point, _CenterPoint As Point, _Degree As Double) As Point() Dim Output() As Point = _Points.Clone() Dim Angle As Double = (_Degree / 180.0) * Math.PI For Index As Integer = 0 To Output.Length - 1 Output(Index) = New Point((Math.Cos(Angle) * (Output(Index).X - _CenterPoint.X)) + _CenterPoint.X, (Math.Sin(Angle) * (Output(Index).Y - _CenterPoint.Y)) + _CenterPoint.Y) Next Return Output End Function
解决方案
Simple: your algorithm is wrong.
See here: Geometric Operations - Rotate[^]
I would suggest that you "break out" each coordinate into a separate set of lines, get X working - obviously, use the debugger to check - and then repeat for Y. When both work, amalgamate the separate stages of X and Y into single lines and create your new point.
Special thanks to OriginalGriff
Public Function RotatePoints2(_Points() As Point, _CenterPoint As Point, _Degree As Double) As Point() Dim Output() As Point = _Points.Clone() Dim Angle As Double = (_Degree / 180.0) * Math.PI For Index As Integer = 0 To Output.Length - 1 Dim Dx As Integer = (Output(Index).X - _CenterPoint.X) Dim Dy As Integer = (Output(Index).Y - _CenterPoint.Y) Output(Index).X = (Math.Cos(Angle) * Dx) - (Math.Sin(Angle) * Dy) + _CenterPoint.X Output(Index).Y = (Math.Sin(Angle) * Dx) + (Math.Cos(Angle) * Dy) + _CenterPoint.Y Next Return Output End Function
这篇关于多边形围绕中心旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文