向左移动(对应逆时针):
//求两点距离
double dist( Point a , Point b )
{
return sqrt( (a-b)*(a-b) );
}
//将线段ab往左移动距离r
void change( Point a , Point b , Point &c , Point &d , double r )
{
double dis = dist( a , b );
double dx = (a.y-b.y)*r/dis;
double dy = (b.x-a.x)*r/dis;
c.x = a.x+dx; c.y = a.y+dy;
d.x = b.x+dx; d.y = b.y+dy;
}
向右移动(对应顺时针):
//求两点距离
double dist( Point a , Point b )
{
return sqrt( (a-b)*(a-b) );
}
//将线段ab往右移动距离r
void change( Point a , Point b , Point &c , Point &d , double r )
{
double dis = dist( a , b );
double dx = (b.y-a.y)*r/dis;
double dy = (a.x-b.x)*r/dis;
c.x = a.x+dx; c.y = a.y+dy;
d.x = b.x+dx; d.y = b.y+dy;
}