📄 point.h
字号:
#ifndef MY_POINT_H
#define MY_POINT_H
/* file: point.h
*/
#include <math.h>
typedef enum{FALSE, TRUE} BOOL;
typedef struct
{
int x;
int y;
}POINT;
/* 求a,b点间距离 */
static float Distance(POINT* a, POINT* b)
{
long x = a->x - b->x;
long y = a->y - b->y;
return sqrt(x*x+y*y);
}/*end Distance*/
/* 求∠abc */
static float Angle(POINT* a, POINT* b, POINT* c)
{
float th;
long xa = a->x - b->x;
long ya = a->y - b->y;
long xc = c->x - b->x;
long yc = c->y - b->y;
long x=xa*xc+ya*yc;
double y=xc*ya-xa*yc;
if( x == 0 )
{
return (y>0.0)?M_PI_2:(-M_PI_2);
}
else {
th=atan(y/x);
if( x<0 )
{
if( th<0.0 )
{
th+=M_PI;
}
else {
th-=M_PI;
}/*end if*/
}/*end if*/
return th;
}/*end if*/
}/*end Angle*/
/* 求与向量pf->pt 同向的单位向量(*px, *py)*/
static void GetDirection(POINT* pf, POINT* pt, float* px, float* py)
{
double dx = pt->x - pf->x;
double dy = pt->y - pf->y;
double m=1.0/sqrt(dx*dx+dy*dy);
*px=dx*m;
*py=dy*m;
}/*end GetDirection*/
/* 将点 p 绕原点旋转 arctan(dy/dx) 度,(dx,dy)为单位向量 */
static void Rotate(POINT* p, float dx, float dy)
{
POINT t=*p;
p->x = 0.5+t.x*dx-t.y*dy;
p->y = 0.5+t.y*dx+t.x*dy;
}/*end Rotate*/
#endif /*define MY_POINT_H*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -