中心旋转 CPoint pointCenter,pointA,pointB;pointA 以 pointCenter为中心旋转角度 X 后的点 pointB是多少?谢谢各位 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我实验写一个: //平移pointCenter到(0,0)点 pointA.X -= pointCenter.X; pointA.Y -= pointCenter.Y; //绕原点旋转pointA获得pointB的坐标 double radin = angle * 3.1415926 / 180.0; //角度转弧度 double sin = Math.Sin(radin); double cos = Math.Cos(radin); pointB.X = pointA.X * cos - pointA.Y * sin; pointB.Y = pointA.X * sin + pointA.Y * cos; //平移回去 pointB.X += pointCenter.X; pointB.Y += pointCenter.Y; 既然自己都知道是三角函数的问题,查一下不就好了。Google也能查出来。 #define M_PI 3.14159265358979323846#define DegToRad(degree) ((degree) * (M_PI / 180.0f)) void MyDraw(HWND hwnd){ RECT device; GetClientRect(hwnd,&device); int cx,cy; cx=device.right; cy=device.bottom; if (cx<cy) { cy=cx; } else { cx=cy; } if (cx%2) { cy=--cx; } HDC hdc; hdc=GetDC(hwnd); SetMapMode(hdc,MM_ANISOTROPIC); int r=100; // scale & xlate SetWindowExtEx(hdc,2*r,2*r,NULL); SetViewportExtEx(hdc,cx,-cy,NULL); SetWindowOrgEx (hdc, 0, 0,NULL); SetViewportOrgEx(hdc,cx/2,cy/2,NULL); // x,y axes MoveToEx(hdc,-r,0,NULL); LineTo (hdc, r,0); MoveToEx(hdc,0,r,NULL); LineTo (hdc,0,-r); // 100-unit circle MoveToEx(hdc,r,0,NULL); AngleArc(hdc,0,0,r,0,360); // eg. for unit circle, in page space, (1,0) counter-clockwise rotate 30 degrees, becomes (cos30,sin30) // we can calculate corresponding coordinate in device page by lptodp POINT p; p.x=(int)(cos(DegToRad(30)) * r); p.y=(int)(sin(DegToRad(30)) * r); MoveToEx(hdc,0,0,NULL); LineTo(hdc,p.x,p.y); // (86,49) ->( 532,146) LPtoDP(hdc,&p,1);} 面试,笔试 都过 等1周通知 心急啊 关于CreateWindowEx创建的窗口风格问题,谢谢! 重装系统后,VS2003下面的项目每次改动所有文件全部重新编译,什么原因呢 自编具有下载功能的浏览器 VSTS的测试问题 oci问题 关于输出的问题 交换机工作在什么层? 这个警告对程序有什么影响? 如何求直线与多边形交点 关于string的问题 WINCE使用CSocket的Recive无法接收完整的数据???
pointA.X -= pointCenter.X;
pointA.Y -= pointCenter.Y; //绕原点旋转pointA获得pointB的坐标
double radin = angle * 3.1415926 / 180.0; //角度转弧度
double sin = Math.Sin(radin);
double cos = Math.Cos(radin); pointB.X = pointA.X * cos - pointA.Y * sin;
pointB.Y = pointA.X * sin + pointA.Y * cos; //平移回去
pointB.X += pointCenter.X;
pointB.Y += pointCenter.Y;
#define DegToRad(degree) ((degree) * (M_PI / 180.0f))
void MyDraw(HWND hwnd)
{
RECT device;
GetClientRect(hwnd,&device);
int cx,cy;
cx=device.right;
cy=device.bottom;
if (cx<cy)
{
cy=cx;
}
else
{
cx=cy;
}
if (cx%2)
{
cy=--cx;
} HDC hdc;
hdc=GetDC(hwnd); SetMapMode(hdc,MM_ANISOTROPIC); int r=100;
// scale & xlate
SetWindowExtEx(hdc,2*r,2*r,NULL);
SetViewportExtEx(hdc,cx,-cy,NULL); SetWindowOrgEx (hdc, 0, 0,NULL);
SetViewportOrgEx(hdc,cx/2,cy/2,NULL); // x,y axes
MoveToEx(hdc,-r,0,NULL);
LineTo (hdc, r,0);
MoveToEx(hdc,0,r,NULL);
LineTo (hdc,0,-r); // 100-unit circle
MoveToEx(hdc,r,0,NULL);
AngleArc(hdc,0,0,r,0,360); // eg. for unit circle, in page space, (1,0) counter-clockwise rotate 30 degrees, becomes (cos30,sin30)
// we can calculate corresponding coordinate in device page by lptodp POINT p;
p.x=(int)(cos(DegToRad(30)) * r);
p.y=(int)(sin(DegToRad(30)) * r); MoveToEx(hdc,0,0,NULL);
LineTo(hdc,p.x,p.y); // (86,49) ->( 532,146) LPtoDP(hdc,&p,1);}