Draw an arc given two points and a radius.
How can I understand the answer given here?
Draw an arc given two points and a radius.
How can I understand the answer given here?
Let start point is S
, end point is E
Center C
lies at middle perpendicular to SE
segment, so we should find vectors:
se = (E.x - S.x, E.y - S.y)
perp = (-se.y, se.x) = (S.y - E.y, E.x - S.x)
perp_normalized = perp / Len(perp)
L = Len(perp) = sqrt((S.y - E.y)^2+(S.x - E.x)^2)
perp_normalized = (S.y - E.y)/L, (E.x - S.x)/L
and middle point of SE
segment
M = ((E.x + S.x)/2, (E.y + S.y)/2)
Distance from M
to circle center is
D = sqrt(R^2-L^2/4)
Now we can express circle center C
coordinates using parametric equation, there are two possible variants:
C = M +/- perp_normalized*D
C1.x = M.x + perp_normalized.x * D
C1.y = M.y + perp_normalized.y * D
C2.x = M.x - perp_normalized.x * D
C2.y = M.y - perp_normalized.y * D
Having center, you can define parameters needed for drawing of arc in your framework
C is the midpoint of DE, so AB and DE are perpendicular (midpoint theorem)
AC=sqrt(AD^2-CD^2) (Pythagoras theorem)
DE=sqrt(AD^2-CD^2) (Pythagoras theorem)
Triangle ACF and EDG are similar triangles, scaled by ratio AC:DE=AF:EG=CF:DG
DG and EG are known. AC and DE are given above. Then we get CF and AF. (And it can be proven that dX(G->D) and dY(C->F) same sign; dX(E->G) and dY(F->A) revsrse sign.)
Therefore we get the center of circle.
And we can get points on the arc by rotating D around A. (rotation formula)