Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Logic behind complex lines

Tags:

c#

algorithm

I want to draw a line from point A to point B. However the lines itself should be intelligent in the sense that if point B is exactly below point A a straight line should get drawn. But if the point B is below A and little far horizontally from A then a line should get drawn in right angled manner. I hope you are getting me. If you may have used any UML tool like edraw Max or any other you may have seen these types of lines. Any idea how can we achieve this?

Thanks in advance :)

like image 299
TCM Avatar asked Feb 26 '11 11:02

TCM


People also ask

What is the main argument of a complex number?

The argument of a complex number is defined as the angle inclined from the real axis in the direction of the complex number represented on the complex plane. It is denoted by “θ” or “φ”. It is measured in the standard unit called “radians”.

How do you explain complex numbers?

Complex numbers are the numbers that are expressed in the form of a+ib where, a,b are real numbers and 'i' is an imaginary number called “iota”. The value of i = (√-1). For example, 2+3i is a complex number, where 2 is a real number (Re) and 3i is an imaginary number (Im).

Why do complex numbers exist?

Complex number are, to use the mathematical term, a “field”, like the real numbers. They have a rule both for addition AND for multiplication. They are not just like that two-dimensional grid. We use complex numbers in physics all the time because they're extremely useful.

What is the purpose of the complex plane?

Just like we can use the number line to visualize the set of real numbers, we can use the complex plane to visualize the set of complex numbers. The complex plane consists of two number lines that intersect in a right angle at the point (0,0)left parenthesis, 0, comma, 0, right parenthesis.


2 Answers

Here's some 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);
}

To clarify, the asker actually wants 3-segment axis-aligned lines that look like most connections here: style

like image 101
Stefan Monov Avatar answered Sep 17 '22 23:09

Stefan Monov


What's the problem with straightforward approach?

// 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
like image 38
Snowbear Avatar answered Sep 17 '22 23:09

Snowbear