D2D画箭头的例子
原文:
D2D画箭头的例子
扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/sunnyloves/article/details/50830102
用处
画流场图的时候需要画出带有箭头的矢量线表示流场
SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。效果图
代码
void ArrowTo(D2D1_POINT_2F start, D2D1_POINT_2F end, ID2D1HwndRenderTarget* pRTarget, ID2D1SolidColorBrush* pBrush)
{
double slopy, cosy, siny;
double length; //length of Arrow
length = 0.05 * sqrt((start.y - end.y)*(start.y - end.y) + (start.x - end.x)*(start.x - end.x));
slopy = atan2((start.y - end.y), (start.x - end.x));
cosy = cos(slopy);
siny = sin(slopy);
D2D1_POINT_2F p[3];
D2D1_POINT_2F start;
start.x = pstart.x;
start.y = pstart.y;
p[0].x = pend.x;
p[0].y = pend.y;
p[1].x = pend.x + length * cosy - (length / 2.0 * siny);
p[1].y = pend.y + length * siny + (length / 2.0 * cosy);
p[2].x = pend.x + length * cosy + length / 2.0 * siny;
p[2].y = pend.y - length / 2.0 * cosy + length * siny;
pRTarget->DrawLine(start, p[0], pBrush);
pRTarget->DrawLine(p[0], p[1], pBrush);
pRTarget->DrawLine(p[0], p[2], pBrush);
}

更多精彩