as can be seen in the figure the location of the point is required. the location of target and obstacle is dynamic but the robot's location can be considered as the center of the universe. what is have done so far is as follows
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));
}
what I need now is the formula that gives me the location of the point.
to make my question more clear please see the following figure and description.
there is a line called A. i have a point in the scene called O . i want to draw a line from the O to the A in a way that when they cross each other the intersection point makes 90 degree angle. plus i want to know what is the intersection point. i want to do it in unity. what i want is a formula.
thank you in advance.