Reputation: 105
In the diagram below, I need to find the midpoint M of the arc from A to B:
I want to find M in terms of the following information:
How do I compute the coordinates of M?
Upvotes: 5
Views: 5661
Reputation: 12195
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;
Upvotes: 7