Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bisector of two vectors in 2D (may be collinear)

How to find a bisecor b = (bx, by) of two vectors in general (we consider two non–zero vectors u = (ux, uy), v = (vx, vy), that may be collinear ).

For non-collinear vector we can write:

bx = ux/|u| + vx / |v|
by = uy/|u| + vy / |v|

But for collinear vectors

bx = by = 0.

Example:

u = (0 , 1)
v = (0, -1)
b = (0, 0)
like image 661
Beginner Avatar asked Oct 26 '25 06:10

Beginner


1 Answers

A general and uniform approach is to get the angle of both vectors

theta_u = math.atan2(ux, uy)
theta_v = math.atan2(vx, vy)

and to create a new vector with the average angle:

middle_theta = (theta_u+theta_v)/2
(bx, by) = (cos(middle_theta), sin(middle_theta))

This way, you avoid the pitfall that you observed with opposite vectors.

PS: Note that there is an ambiguity in what the "bisector" vector is: there are generally two bisector vectors (typically one for the smaller angle and one for the larger angle). If you want the bisector vector inside the smaller angle, then your original formula is quite good; you may handle separately the special case that you observed for instance by taking a vector orthogonal to any of the two input vectors (-uy/|u|, ux/|u|) if your formula yields the null vector.

like image 65
Eric O Lebigot Avatar answered Oct 29 '25 06:10

Eric O Lebigot



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!