The logic behind complex lines

I want to draw a line from point A to point B. However, the lines themselves must be intelligent in the sense that if point B is exactlybelow point A, a straight line should be drawn . But if point B is below A and a little far horizontal from A, then the line should be drawn in a rectangular manner. I hope you catch me. If you may have used any UML tool, such as edraw Max or any other, you could see these line types. Any idea how we can achieve this?

Thanks in advance:)

+5
source share
4 answers

Here is the code:

void connectPoints(Point a, Point b)
{
    Point middlePoint1(a.x, (a.y + b.y)/2);
    Point middlePoint2(b.x, (a.y + b.y)/2);
    drawLine(a, middlePoint1);
    drawLine(middlePoint1, middlePoint2);
    drawLine(middlePoint2, b);
}

, , : style

+4

?

// pA, pB - points
DrawLine(pA.X, pA.Y, pA.X, pB.Y); // vertical line from A point down/up to B
DrawLine(pA.X, pB.Y, pB.X, pB.Y); // horizontal line to B
+1

, ? ...

Point pA(x,y);
Point pB(x,y);
if abs(pB.X-pA.X) < abs(pB.Y-pA.Y) // Going vertically or horizontal?
{
    DrawLine(pA.X, pA.Y, pA.X, pB.Y); //Long vertical
    DrawLine(pA.X, pB.Y, pB.X, pB.Y); //Short horizontal
}
else
{
    DrawLine(pA.X, pA.Y, pB.X, pA.Y); //Long horizontal
    DrawLine(pB.X, pA.Y, pB.X, pB.Y); //Short vertical
}

( ):

Point pA=(x,y);
Point pB=(x,y)
if abs(pB.X-pA.X) < abs(pB.Y-pA.Y) // Going vertically or horizontal?
{
    Point pHalfwayY = (pB.Y-pA.Y)/2 + pB.Y
    DrawLine(pA.X, pA.Y, pA.X, pHalfwayY ); //Long vertical 1st half
    DrawLine(pA.X, pHalfwayY , pB.X, pHalfwayY ); //Short horizontal
    DrawLine(pA.X, pHalfwayY , pA.X, pB.Y); //Long vertical 2nd half
}
else
{
    Point pHalfwayX = (pB.X-pA.X)/2 + pB.Y
    DrawLine(pA.X, pA.Y,pHalfwayX , pA.Y); //Long horizontal 1st Half
    DrawLine(pHalfwayX , pA.Y, pHalfwayX , pB.Y); // Short Vertical
    DrawLine(pHalfwayX , pA.Y, pA.X, pB.Y); //Long horizontal 2nd half
}

, .

+1

, GDI +, , .

, , .

0

All Articles