Draw an arrow between two circles?

后端 未结 4 989
再見小時候
再見小時候 2021-02-10 07:31

How can I draw an arrowed line between two circles, given:

  1. Location of the centers of the cirlces
  2. Radius of the circles

I am using

4条回答
  •  心在旅途
    2021-02-10 08:15

    If I understood correctly, you need to find the 2D vector that you need to add to the source to get to the border of the target circle.

    Pseudo code:

    d = distance between A and B; // (sqrt((xB-xA)² + (yB-yA)²)).
    d2 = d - radius;
    
    ratio = d2 / d;
    
    dx = (xB - xA) * ratio;
    dy = (yB - yA) * ratio;
    
    x = xA + dx;
    y = yA + dy;
    

提交回复
热议问题