二维中两个向量的等分线(可能是共线的) [英] Bisector of two vectors in 2D (may be collinear)

查看:182
本文介绍了二维中两个向量的等分线(可能是共线的)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常如何找到两个向量的二等分b =(bx,by)(我们考虑两个非零向量u =(ux,uy),v =(vx,vy),这可能是共线的).

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|

但是对于共线向量

bx = by = 0.

示例:

u = (0 , 1)
v = (0, -1)
b = (0, 0)

推荐答案

一种通用且统一的方法是获取两个向量的角度

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 :请注意,平分线"矢量是一个歧义:通常有两个平分线矢量(通常一个用于较小的角度,一个用于较大的角度).如果您希望平分线向量在较小的角度内,那么您的原始公式就很好.您可以单独处理所观察到的特殊情况,例如,如果公式产生的是空向量,则通过取与两个输入向量(-uy/|u|, ux/|u|)中的任何一个正交的向量来实现.

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.

这篇关于二维中两个向量的等分线(可能是共线的)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆