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;
{Arrowheads[ah], Arrow[{tail, tail + v}]
, 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).

  • $\begingroup$ 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? $\endgroup$ – Lukas Lang Jun 10 '18 at 20:44
  • $\begingroup$ (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? $\endgroup$ – kglr Jun 11 '18 at 7:11
  • $\begingroup$ 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}] :) $\endgroup$ – Bll.Bamdad Jun 11 '18 at 14:28
  • $\begingroup$ 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. $\endgroup$ – Steven Thomas Hatton Jun 11 '18 at 17:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.