绘制带箭头的直线【MFC】

有些参数还可以进行提取优化,目前只能算个雏形。

void drawArrow(CDC* pDC,CPoint start,CPoint end) {
	double PI = acos(-1);
	pDC->SelectObject(new CPen(PS_SOLID, 1, RGB(0, 0, 0)));
	pDC->MoveTo(start);
	pDC->LineTo(end);
	CPoint l, r;
	if (start.x == end.x) {
		int y = 9;
		if (end.y > start.y)y = -y;
		CPoint right(end.x-5,end.y+y), left(end.x + 5, end.y + y);
		l = left;
		r = right;
	}
	else {
		//获取斜率
		double angle = atan(1.0*(end.y - start.y) / (end.x - start.x));
		int rarrowx = end.x - 10 * cos(PI / 6 + angle);
		int rarrowy = end.y - 10 * sin(PI / 6 + angle);
		int larrowx = end.x - 10 * sin(PI / 3 + angle);
		int larrowy = end.y + 10 * cos(PI / 3 + angle);
		CPoint right(rarrowx, rarrowy), left(larrowx, larrowy);
		l = left;
		r = right;
	}
	pDC->MoveTo(r);
	pDC->LineTo(end);
	pDC->MoveTo(l);
	pDC->LineTo(end);
}
上一篇:计算两点与正北方向夹角


下一篇:MATLAB产生变换图片