You are right, this method is not working for all the cases. The problem is with step #3. What you should do first is try to determine the kind of your line, it means to figure whether P is to the left from Q, or to the right, and is P above Q or below.
For example, let's say we have P(p1, p2) and Q(q1, q2).
Case 1:
p1 < q1 and p2 < q2
Case 1:
p1 < q1 and p2 < q2
To copy to clipboard, switch view to plain text mode
Your line will look like this
. * Q
/
/
/
* P
. * Q
/
/
/
* P
To copy to clipboard, switch view to plain text mode
It means that your new point P` will be above P. That;s why you take P.x() + some_value and then calculate new value for P.y() from that equation.
Case 2:
p1 > q1 and p2 < q2
Case 2:
p1 > q1 and p2 < q2
To copy to clipboard, switch view to plain text mode
Q *
\
\
\
* P
Q *
\
\
\
* P
To copy to clipboard, switch view to plain text mode
in this case you'll have to take P.x() - some_value.
And so on, and so forth...
I hope you get the idea.
Bookmarks