# Get the direction vector passing through the intersection point of two straight lines

Let say I have this diagram,

How to find the direction vector passing through the intersection point of two straight lines?

Update: new vector is the bisector of two lines and vector may be arbitrary.

-
Do you mean for that vector to be the angle bisector of the other two? –  Gerry Myerson Apr 3 '12 at 10:12
yes I mean this –  user960567 Apr 3 '12 at 10:14
Then why don't you edit the question so it says what you actually mean? –  Gerry Myerson Apr 3 '12 at 13:06
@GerryMyerson, updated now. Thanks. Can you please answer this if you can? –  user960567 Apr 3 '12 at 13:11
What's wrong with the two answers you already have? Anyway, I'm afraid it's bedtime now. It will have to wait until tomorrow. –  Gerry Myerson Apr 3 '12 at 13:20

Normalize the two given vectors, i.e. compute $$e_a:={a\over |a|}={1\over\sqrt{13}}(2,3)\ ,\quad e_b:={b\over|b|}={1\over\sqrt{5}}(2,1)\ .$$ Then the angle bisector will pass through the point $$p:=e_a+e_b=\Bigl({2\over\sqrt{13}}+{2\over\sqrt{5}},{3\over\sqrt{13}}+{1\over\sqrt{5}}\Bigr)\doteq(1.44913,1.27926)$$ whose argument is $\arctan(0.882782)=0.723221=41.44^\circ$.

The following figure shows the geometric intuition behind the above computation:

-
I think is not correct see the above calculations –  user960567 Apr 3 '12 at 17:48
@user960567: My values coincide with the results of Dennis Gulko and pedja. –  Christian Blatter Apr 3 '12 at 19:59
Yes got that. This seems to me more straight forward. Is this work for a vector between any 2 points? Can you please show me how? –  user960567 Apr 4 '12 at 3:55
I have extensively tested all solutions. But your solution is always gives me correct values in my application. Dennis solution is also fine but sometimes I cannot get desired result. Your solution is also very very simple. Can you explain a little how you found this formula? –  user960567 Apr 4 '12 at 6:20
@user960567: I did what you would do to solve this problem with ruler and compass: Draw a circle with center at the intersection of the two lines; then construct the median of the two points where the circle intersects the two lines. –  Christian Blatter Apr 4 '12 at 7:56

Let's denote direction vector as $v$ ,then :

$$v=\left(1,\tan\left(\frac{\arctan{\frac{3}{2}}+\arctan{\frac{1}{2}}}{2}\right)\right)\approx(1,0.8828)$$

-
I am not getting 1.1328 result. Can you please check it? –  user960567 Apr 3 '12 at 10:54
@user960567 fixed –  pedja Apr 3 '12 at 11:03
Not sure but you have different value than @DennisGulko. –  user960567 Apr 3 '12 at 11:11
@user960567 Our solutions are basically the same... –  pedja Apr 3 '12 at 11:15
PLease see the comment above if you can answer this. –  user960567 Apr 3 '12 at 12:15

It seems that what OP really wants is, given direction vectors $(1,a)$ and $(1,b)$, find the direction vector of their angle bisector.

I'm going to assume $0\le a\le b\lt\infty$, and let OP figure out the necessary modifications if any for other parameter ranges.

Let $\alpha$ be the angle the 1st direction vector makes with the $x$-axis, and let $\beta$ be the angle the 2nd direction vector makes with the $x$-axis. Then we have $\tan\alpha=a$, and $\tan\beta=b$. The bisector makes an angle $(\alpha+\beta)/2$ with the $x$-axis, so its direction vector is $(1,\tan((\alpha+\beta)/2))$. By the half-angle formula for the tangent (see, e.g., http://en.wikipedia.org/wiki/Tangent_half-angle_formula) we have $$\tan\left({\alpha+\beta\over2}\right)={\tan(\alpha+\beta)\over1+\sqrt{1+\tan^2(\alpha+\beta)}}$$ Combine this with the addition formula for the tangent, $$\tan(\alpha+\beta)={\tan\alpha+\tan\beta\over1-\tan\alpha\tan\beta}$$ and the values $\tan\alpha=a$ and $\tan\beta=b$ already mentioned, and you have a formula for the direction vector $(1,\tan((\alpha+\beta)/2))$ of the bisector. I think that second component simplifies to $${a+b\over1-ab+\sqrt{(a^2+1)(b^2+1)}}$$

-
Thanks. But I found Christian Blatter solution is very simple and always gives correct result for any two vectors. –  user960567 Apr 4 '12 at 6:21

You can do this by calculating the angle between the two and then finding the appropriate direction vector. Using that the angle between line passing through the points $(0,0)$ and $(x,y)$ and between the $x$-axis is given by $\arctan\frac{y}{x}$.
Then the angle between the given two lines will be: $\arctan\frac{3}{2}-\arctan\frac{4}{8}$ (do you see why?)
So, the angle between the desired line and the $x$-axis will be: $$\frac{1}{2}\left(\arctan\frac{3}{2}-\arctan\frac{1}{2}\right)+\arctan\frac{1}{2}=\frac{1}{2}\left(\arctan\frac{3}{2}+\arctan\frac{1}{2}\right)$$ Once again - do you see it?
Now, the direction vector will be $(1,y)$, where $y=\tan\left[\frac{1}{2}\left(\arctan\frac{3}{2}+\arctan\frac{1}{2}\right)\right]$.
You can calculate it with a calculator or using the identities of the $\tan$ and $\arctan$ functions.
Edit: The $\arctan$ function returns values between $-\frac{\pi}{2}$ and $\frac{\pi}{2}$ rad ($-90$ and $90$ degrees). So, if a point $(x,y)$ is in the first or fourth quadrant, then the angle between the line and the $x$-axis will be in that interval and will be exactly $\arctan\frac yx$. But if it's not, then you have to "repair" the angle: If $(x,y)$ is in the second quadrant (i.e. $x<0, y>0$) then the angle should be between $\frac{\pi}{2}$ and $\pi$ rad. The correct way to get the angle will be $\pi+\arctan\frac yx$.
If $(x,y)$ is in the third quadrant (i.e. $x<0, y<0$) then the angle should be between $-\pi$ and $-\frac{\pi}{2}$ rad. The correct way to get the angle will be $-\pi+\arctan\frac yx$.
(If you're used to calculating in degrees, replace $\pi$ by $180$ degrees everywhere).
Edit 2: If you want to calculate the angle of a line passing through two given points $(x_1,y_1)$, $(x_2,y_2)$ with the $x$-axis, You should replace each $\arctan\frac yx$ with $\arctan\frac {y_2-y_1}{x_2-x_1}$

-
Thanks. I will check it with my application and let you know –  user960567 Apr 3 '12 at 10:54
You should get $\frac18(\sqrt{65}-1)\approx 0.8827$ –  Dennis Gulko Apr 3 '12 at 11:00
Not sure but you have different value than @pedja. –  user960567 Apr 3 '12 at 11:07
@user960567: Yes, it will, as long as both $(x_1,y_1)$ and $(x_2,y_2)$ are in the first quadrant. If they are not, then, in some cases, the values of $\arctan$ need to be corrected by $\pi$, to have the correct angle. –  Dennis Gulko Apr 3 '12 at 11:24
@user960567: I edited my post and added the correct way to calculate angles with the $x$-axis. You should be able to continue from here. –  Dennis Gulko Apr 3 '12 at 19:46