15,741,818 members
See more:
Hi,
I have two point (x1,y1) and (x2,y2) which makes a straight line. Now I want to draw two lines through the terminal points which will be perpendicular to the main line.

in attached image you can see what i need.

Posted
Updated 30-Dec-15 2:02am
v4
Richard MacCutchan 30-Dec-15 5:03am
You would do it by writing some code. Your link does not seem to contain any useful information, please edit your question and explaion in better detail.
[no name] 30-Dec-15 9:13am
A vector prependicular to (a,b) is (-b,a). This one can prove by the help of scalar product.
Now with this (-b,a) vector one can easily calculate the four (?,?) vectors respectively their representants.
Sergey Alexandrovich Kryukov 30-Dec-15 13:10pm
The problem is ambiguous, because you can draw multiple perpendicular lines.
—SA
[no name] 30-Dec-15 13:44pm
Nothing is ambiguous, except the abs() of the perpendicular vectors.
Sergey Alexandrovich Kryukov 30-Dec-15 15:46pm
You are right: I noticed that the inquirer needs two lines "through the terminal points". Of course, this is solvable. And "abs of perpendicular vector" also does not make things ambiguous, because the question is not about the vector. It's enough to point out two points per straight line, "representative enough"; ideally, the points at the interception of these lines to the viewport boundaries (or beyond this boundary).
—SA

## Solution 1

A vector perpendicular to (a,b) is (-b,a). This one can prove by the help of scalar product (also named dot product).

In your case (a,b)= (x2,y2)-(x1,y1). Now, with this (-b,a) vector one can easily calculate the four (?,?) vectors respectively their “representants” (sorry I do not find the right word in English).

Because (?,?) is not specified more precise, I personally would use the above mentioned calculations. Another way is to use “unit vector” for (-b,a), but in case of graphics one has to pay attention, not to lose precisions.

Sorry for my bad English, I hope it helps.

It is simple vector computation. Even if others here think it is more.

v2
Sergey Alexandrovich Kryukov 30-Dec-15 12:52pm

How (a, b) and (a, -b) can be perpendicular? Can't you see that (100, 1) and (100, -1) are positioned at sharp angle?

"Find a perpendicular line" is ambiguous. The question is not about finding a perpendicular vector, it's about finding two points. You can draw multiple perpendicular lines...

—SA
[no name] 30-Dec-15 12:57pm
Sorry, I forgot to mention the trivial Solutions as an "exception"... but I think OP Needs first to consume the non trivial ones :-)

It is up to you to describe it more precisely.
Bruno

This comment is not longer valid after edit of SA's comment
Sergey Alexandrovich Kryukov 30-Dec-15 12:59pm
Sorry, I fixed my comment above. The whole problem is posed ambiguously, and your post is plain wrong.
—SA
[no name] 30-Dec-15 13:19pm
Sergey Alexandrovich Kryukov 30-Dec-15 15:41pm
My mistake, sorry. I'll try to fix it.
—SA

## Solution 2

i did the same by using the following code

dx = x1-x2
dy = y1-y2
dist = sqrt(dx*dx + dy*dy)
dx /= dist
dy /= dist
x3 = x1 + (N/2)*dy // where N is the length of line to be draw.
y3 = y1 - (N/2)*dx
x4 = x1 - (N/2)*dy
y4 = y1 + (N/2)*dx

and same way i found the x5,y5 and x6 y6.