D2D画箭头的例子

用处

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

效果图

直接看箭头图效果
D2D画箭头的例子_第1张图片

代码

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

}

你可能感兴趣的:(流场,Direct2D,箭头图)