平面中,一個點(x,y)繞任意點(dx,dy)順時針旋轉a度後的座標ios
xx= (x - dx)*cos(-a) - (y - dy)*sin(-a) + dx ;spa
yy= (x - dx)*sin(-a) + (y - dy)*cos(-a) +dy ;io
平面中,一個點(x,y)繞任意點(dx,dy)逆時針旋轉a度後的座標stream
xx= (x - dx)*cos(a) - (y - dy)*sin(a) + dx ;gc
yy= (x - dx)*sin(a) + (y - dy)*cos(a) +dy ;di
C++實現:co
#include "stdafx.h"
#include <math.h>
#include <iostream>
#include <stdio.h>
#define PI 3.141592654
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int x = 1, y = 2;//旋轉的點
int dx = 1, dy = 1;//被繞着旋轉的點
for (int i = 0; i <= 8; i++)
{
//int angle = 45 * i;//逆時針
int angle = -45 * i;//順時針
double xx = (x - dx)*cos(angle * PI / 180) - (y-dy)*sin(angle * PI / 180) + dx;
double yy = (y-dy)*cos(angle * PI / 180) + (x-dx)*sin(angle * PI / 180) + dy;
cout << xx <<'\t'<< yy << endl;
}
return 0;
}
math