简洁版本:
基本上,我正在尝试使用( )Point C的终点来计算未知数的 X 和 Y 值。Line ABPoint B
我尝试使用atan2( B.y, B.x),但它给了我相对于X-Axis导致错误坐标的角度。我想我需要得到由( ) 构成的角度Line BC和假想的水平轴。有没有办法获得那个角度?如果获得那个角度不会做我想做的事,那会怎样?Point BAngle P
长版:
我正在尝试使用 C++ 进行一些数学运算,但我遇到了这个特定问题。
我有两个向量,Vector A和Vector B(由Point Aand说明Point B,它们形成line AB)。现在,我想得到Vector C( Point C),它是L距离Vector B( 用Line BC) 表示的单位。

我四处搜索,阅读了一些书,并得到了这个公式来得到我需要的观点。
/* Let:
* L = length from B to C
* ( B.x, B.y ) = start point
* ( C.x, C.y ) = end point
* theta = angle respective to X-Axis ( using atan2( B.y, B.x ) )
*/
// To get C.x use formula cos( theta ) = ( C.x - B.x ) / L then derive
C.x = ( L * cos( theta ) ) + B.x;
// To get C.y use formula sin( theta ) = ( C.y - B.y ) / L then derive
C.y = ( L * sin( theta ) ) + B.y;
但是,这不会导致Point C如上所示,因为结果C将与X-Axis. 在阅读了更多之后,我发现我需要得到(淡红色线)和假想的水平轴(蓝绿色线)Angle P之间的角度(用紫色表示) 。Line BCPoint B
另一个例子:

在这种情况下,使用上面的公式会导致C在错误的地方(上面( X , 5 ))
我不确定gettingAngle P是否会做我想做的事,如果您知道更合适的答案,请这样做。