// C# Program to rotate an object by
// a given angle about a given point
using System;
class rotation
{
// Function to rotate the given points
// about the pivot point by angle
static void rotate(double[,] a, int n,
int x_pivot, int y_pivot, int angle)
{
int i = 0;
while (i < n)
{
// Shifting the pivot point to the origin
// and the given points accordingly
int x_shifted = (int)a[i, 0] - x_pivot;
int y_shifted = (int)a[i, 1] - y_pivot;
// Calculating the rotated point co-ordinates
// and shifting it back
double x = Math.PI * angle / 180.0;
a[i, 0] = x_pivot + (x_shifted *
Math.Cos(x) - y_shifted *
Math.Sin(x));
a[i, 1] = y_pivot + (x_shifted *
Math.Sin(x) + y_shifted *
Math.Cos(x));
Console.Write("({0}, {1}) ",
a[i, 0], a[i, 1]);
i++;
}
}
// Driver Code
public static void Main(String[] args)
{
// 1st Example
// The following figure is to be
// rotated about (0, 0) by 90 degrees
int size1 = 4; // No. of vertices
// Vertex co-ordinates must be in order
double[,] points_list1 = { { 100, 100 },
{ 150, 200 },
{ 200, 200 },
{ 200, 150 } };
rotate(points_list1, size1, 0, 0, 90);
// 2nd Example
// The following figure is to be
// rotated about (50, -50) by -45 degrees
/*int size2 = 3;//No. of vertices
double[,] points_list2 = { { 100, 100 },
{ 100, 200 },
{ 200, 200 } };
rotate(points_list2, size2, 50, -50, -45);*/
}
}