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

2019-07-02 13:24发布

问题:

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)

回答1:

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.



回答2:

To find the unit bisection vectors of u and v.

if u/|u|+v/|v| !=0

first calculate the unit vector of u and v

then use the parallelogram rule to get the bisection (just add them)

since they both have unit of 1, their sum is the bisector vector 

then calculate the unit vector of the calculated vector.

else (if u/|u|+v/|v| ==0):
 (if you use the method above, it's like a indintermination: 0*infinity=?)

 if you want the bisector of (u0v) if u/|u| = (cos(t),sin(t)) 
 take b=(cost(t+Pi/2),sin(t+Pi/2)) = (-sin(t),cos(t) )as the bisector
 therefore if u/|u|=(a1,a2) chose b=(-a2,a1)

Example:

u=(0,1)
v=(0,-1)
the bisector of (u0v):
b=(-1,0)