如图所示,点的位置是必需的。目标和障碍物的位置是动态的,但机器人的位置可以被视为宇宙的中心。到目前为止,我们所做的是:
float m = calculate_m();
float d = calculate_d(nearest_obstacle, m);
teta = (float)calculate_angle(d, nearest_obstacle);
float calculate_m()
{
float m = (player.position.z - winning_state.position.z )/(player.position.x - winning_state.position.x);
return m;
}
float calculate_d(Transform nearest_obstacle,float m)
{
float b;
b = (-1 * player.position.z) + (m * player.position.x);
//changed: we remove || absolute value so it gives -90 90 degree ||
float d = (nearest_obstacle.position.z - (m * nearest_obstacle.position.x) + b) / (Mathf.Sqrt(Mathf.Pow(m, 2) + Mathf.Pow(1, 2)));
return d;
}
float calculate_angle(float d,Transform nearest_obstacle)
{
float pw_distance=my_distance(player.position.x,nearest_obstacle.position.x,player.position.z,nearest_obstacle.position.z);
float mycalcInRadians = Mathf.Asin(d/pw_distance);
float mycalcInDegrees = mycalcInRadians * 180 / Mathf.PI;
return mycalcInDegrees;
}
float my_distance(float x1,float x2,float z1,float z2)
{
return Mathf.Sqrt (Mathf.Pow(x1-x2,2)+Mathf.Pow(z1-z2,2));
}
我现在需要的是给我点的位置的公式。
为了让我的问题更清晰,请参见以下图示和描述。
有一条线段叫做A。场景中有一个点叫做O。我想要从O到A画一条直线,使得它们交叉时交点成为90度角。此外,我想知道交点在哪里。我想在Unity中实现这个功能,所需的是一个公式。
提前感谢你。