1
$\begingroup$

I am generating successive arrows to represent vectors, but when they coincide all the arrowheads disappear except the last. But since they are vectors I want to keep all arrowheads to show direction. Is there a way to do this? Below is code. Also, this would't work until I used Evaluate on the Arrow, but I'm unsure why. Could someone explain? Tks. (This works but is incomplete since I still have to make x[[n]] depend on len)

vectors = {0, 0, 3, 2, 3, 2, -1, 3, 4, 0};
len = Length[vectors]/2;
x = Partition[vectors, 2];
slots = Slot /@ Range[len];
t = Graphics[
  Evaluate[Arrow[slots]] &[x[[1]], x[[2]], x[[3]], x[[4]], x[[5]]], 
  Axes -> True, AxesOrigin -> {0, 0}]
$\endgroup$
2
  • $\begingroup$ I think what you want is Graphics[Arrow /@ Partition[x, 2, 1], Axes -> True, AxesOrigin -> {0, 0}]? There's no need for Slot kluge. $\endgroup$
    – march
    Apr 13, 2023 at 5:27
  • $\begingroup$ Well, that certainly simplifies things 😁 $\endgroup$ Apr 13, 2023 at 5:45

2 Answers 2

2
$\begingroup$

Try this:

    vectors = {0, 0, 3, 2, 3, 2, -1, 3, 4, 0};
    x = Partition[vectors, 2];
    Graphics[Map[Arrow, 
  Partition[Drop[Drop[Flatten[x /. {a_, b_} -> {{a, b}, {a, b}}, 1], 1], -1],2]]]

enter image description here

Have fun!

$\endgroup$
1
$\begingroup$
 Graphics @ BlockMap[Arrow @ Partition[#, 2] &, vectors, 4, 2]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.