15,959,738 members
See more:
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
```
Posted
Updated 18-Jan-18 0:35am
Kornfeld Eliyahu Peter 18-Jan-18 5:50am
point-by-point?
mashali 18-Jan-18 6:45am
thanks. problem solved, my algorithm was wrong.

## Solution 1

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.

mashali 18-Jan-18 6:32am
Thanks OriginalGriff
its work :)
OriginalGriff 18-Jan-18 6:39am
You're welcome!

## Solution 2

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
```