D2D画箭头的例子

原文: D2D画箭头的例子

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/sunnyloves/article/details/50830102

用处

画流场图的时候需要画出带有箭头的矢量线表示流场

效果图

直接看箭头图效果
效果

代码

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);

}

猜你喜欢

转载自www.cnblogs.com/lonelyxmas/p/10823158.html
今日推荐