2
votes

In the diagram below, I need to find the midpoint M of the arc from A to B:

midpoint

I want to find M in terms of the following information:

  • A.X and A.Y, the coordinates of A
  • B.X and B.Y, the coordinates of B
  • Radius, the radius of the arc
  • Center.X and Center.Y, the center of the arc

How do I compute the coordinates of M?

1
There literally isn't a question here. - Preston Guillot
Sounds like an interesting problem. How far did you get on solving it? - Roman
The question is how to what algorithm i need to use to find the X and Y of the midpoint of the arc? - michaelbr92
and no i don't have the attitude of the mid point - michaelbr92
Isn't this maths rather than programming? - MrKWatkins

1 Answers

6
votes

Assuming A, B, M and Center are objects of some vector type with the usual operations:

var a = A-C;
var b = B-C;
var m = a+b;

m is a vector that goes from Center towards M. Therefore:

m = m.Normalize() * Radius;
M = Center + m;

Please note: This algorithm does not assume an order of A and B, and always interprets the arc as the smaller of the two possible ones. Without adding special cases, it can only handle arcs with an angle smaller than 180°.

To handle order: First calculate the angle from a to b using atan2:

var angle = Math.Atan2(b.y, b.x) - Math.Atan2(a.y, a.x);
if (angle < 0)
{
    angle = 2*Math.PI + angle;
}

Then rotate a by half that angle:

angle /= 2;
var m = a.Rotate(angle);
M = Center + m;