I have a label which is linked to an anchor. The problem is to find on which one of the four side of the label (which is a Rectangle) should be linked to the anchor.
So I created a vector from the label center to the top right of the label (v1), a vector from the center to the bottom right (v2), to the top left (v3) and bottom left (v4). I also create a vector from the center of the label to my anchor (v).
My problem is to find if v is between (v1,v2) , (v1,v3) , (v1, v4) or(v4, v2) so I can know from which side I should link my anchor.
to calculate if a vector v is between v1 and v2 I use the following formula :
(crossProduct v1, v >= 0 and crossProduct v, v2 >= 0) or (crossProduct v1, v <= 0 and crossProduct v, v2 <= 0)
where crossProduct is calculated with the following formula:
v1.y * v2.y - v1.x * v2.x
However I'm not able to find the correct side of the rectangle.