# How to dynamically position labels in 2D Graphics?

I wrote the following function to put labels on vectors in my graphics.

LabeledArrow[length_, angle_, label_, tail_:{0,0}, Dn_:1, Dt_:0, ah_:Medium] :=
Module[{v, dn}
,v=length {Cos[angle],Sin[angle]}; dn=.02 Dn;
, Text[label, tail + v/2 (1 + Dt) + dn Normalize[{-v[[2]], v[[1]]}]]}
]


It works without having to fine-tune the positioning when the arrows are the only graphics objects, and they are of unit length with their tails at the origin. But if I add objects which increase the coordinate range of the image, my labels are no longer nicely positioned as before. I added the optional argument Dn so that the displacement of the label normal to the arrow can be adjusted. But that requires that I change Dt whenever the scaling changes.

Is there a way to write a function that will dynamically adjust this positioning when the coordinate range of the graphics changes?

I'm using 10.4.0 for Microsoft Windows (64-bit) (February 26, 2016).

• Could you provide a few examples of how it looks currently (with the code to generate them) and how you'd like it to look? – Lukas Lang Jun 10 '18 at 20:44
• (1) Use the third argument of Text, e.g. Text[label, tail + v/2 (1 + Dt) + dn Normalize[{-v[[2]], v[[1]]}], Right], or (2) use Offset to fine-tune the position of the text, e.g., Text[label, Offset[{-10, 0}, tail + v/2 (1 + Dt) + dn Normalize[{-v[[2]], v[[1]]}]]], (3) or both? – kglr Jun 11 '18 at 7:11
• I don't know exactly what u said but suppose that u have a x[t] & y[t] u can use this code to see dynamical position vector as a function of t Animate[PointPlot[{{x[t],y[t]},{0,0}}],{t,0,tMax}] :) – Bll.Bamdad Jun 11 '18 at 14:28
• That begs the question of how to dynamically adjust the offset. I have thought about having a nested function to automatically adjust the offset, depending upon the relative positioning of the labeled object. But that would not dynamically scale to the coordinate dimensions of the graphics. I will work on providing an example, as suggest by Mathe172. – Steven Thomas Hatton Jun 11 '18 at 17:07