Optimize Path Distance From Circle Calculation In D3
In this D3.js graph I'm using the magic numbers 20 when the line is straight and 30 when the line is at an angle as the margin to withdraw from the path in order to add a margin be
Solution 1:
As far I understand - you have center of the first circle (x0,y0), center of the second circle (x1,y1), circle radius R, desired margin from circle circumference M, and want to find starting and ending coordinates of arrow.
(Seems you are using full distance from circle center, in this case set Marg)
dx = x1 - x0
dy = y1 - y0
Len = math.sqrt(dx * dx + dy * dy) //use math.hypot if available
Marg = R + M //full distance from circle center to arrow end. 30 in your case
Coeff = Marg / Len
ax0 = x0 + Coeff * dx //arrow start coords
ay0 = y0 + Coeff * dy
ax1 = x1 - Coeff * dx //arrow end
ay1 = y1 - Coeff * dy
That's all.
Post a Comment for "Optimize Path Distance From Circle Calculation In D3"