平面坐标变换
[編輯] [转简体] (简体译文)
|
作者:zouhaiyuan
| 分類:【算法】2D、3D 相關算法
[
26 瀏覽
0 評論
7 贊
9 踩
]
概要
平面坐标变换
正文
#include <stdlib.h> #include <stdio.h> #include <math.h> #define PI3.1415927 typedef struct _Point_ { double x; double y; double angle; } POINT; double AngleToRadian(double p_pAngle) { double Radian = PI*p_pAngle/180; return Radian; } double RadianToAngle(double p_pRadian) { return 180*p_pRadian/PI; } int main() { //double PI = 3.1415927; POINT orgPoint1 = {0,0,0};//初始原点 POINT orgPoint2 = {0,0,270};//变换后的原点 POINT p1 = {2,1,0};//变换前的点 POINT p2 = {0,0,0};//变换后的点 double L = sqrt(p1.x*p1.x + p1.y*p1.y); double Afa = AngleToRadian(orgPoint2.angle);//变换后与原坐标系X轴的夹角 double Belta = asin(p1.y/L);//原坐标点与X轴的夹角 double Germa = Belta - Afa; p2.x = L*cos(Germa); p2.y = L*sin(Germa); printf("原点(%.2f,%.2f)\r\n",orgPoint1.x,orgPoint1.y); printf("变换后的原点(%.2f,%.2f),角度 %.2f\r\n",orgPoint2.x,orgPoint2.y,orgPoint2.angle); printf("斜边长度(%.2f)\r\n",L); printf("贝塔 变换前点与X轴的夹角 弧度(%.2f) 角度(%.2f)\r\n",Belta,RadianToAngle(Belta)); printf("伽马 弧度(%.2f) 角度(%.2f)\r\n",Germa,RadianToAngle(Germa)); printf("变换后的点(%.2f,%.2f)\r\n",p2.x,p2.y); getchar(); return 0; }