7
$\begingroup$

I have:

Graphics[{
  Blue, Thick,
  Arrow[{{0, 0}, f1}],
  Arrow[{{0, 0}, f2}],
  Red, Arrow[{{0, 0}, f1 + f2}],
  Dashed, Blue,
  Line[{{-9, 0}, {12, 0}}]
  }]

Which produces this image.

enter image description here

Now, I want to continue, adding another line to my code, after the last line. I want to change from Dashed to solid again. How do I do that?

Result due to helpful suggestions:

f1 = 10 {Cos[135 °], Sin[135 °]};
f2 = 12 {Cos[30 °], Sin[30 °]};

Followed by:

Graphics[{
  Blue, Thick,
  Arrow[{{0, 0}, f1}],
  Arrow[{{0, 0}, f2}],
  Red, Arrow[{{0, 0}, f1 + f2}],
  Dashed, Blue,
  Line[{{-9, 0}, {12, 0}}],
  Thickness[0.005], Arrowheads[Medium],
  Dashing[None], 
  Arrow[Table[5 {Cos[t], Sin[t]}, {t, 0, π/6, π/100}]],
  Arrow[Table[3 {Cos[t], Sin[t]}, {t, 0, 3 π/4, π/100}]],
  Red, Arrow[Table[4 {Cos[t], Sin[t]}, {t, 0, 1.3, π/100}]],
  Text[Style["F1", Blue], f1, {0, -1}],
  Text[Style["F2", Blue], f2, {0, -1}],
  Text[Style["F1+F2", Red], f1 + f2, {0, -1}],
  Text[Style["30°", Blue], 
   5.5 {Cos[13 °], Sin[13 °]}, {-1, 0}],
  Text[Style["135°", Blue], 
   3.5 {Cos[100 °], Sin[100 °]}, {0, -1}],
  Text[Style["θ", Red], 
   4.5 {Cos[50 °], Sin[50 °]}, {0, -1}],
  }]

Which produces the following image.

enter image description here

So folks were very helpful.

$\endgroup$
2
  • 4
    $\begingroup$ Within Graphics[], you can use lists to localize the effect of a directive on a primitive. So, Graphics[{Blue, Line[{{0, 0}, {1, 0}}], Line[{{0, 0}, {1, 1}}]}] will render both lines blue, but Graphics[{{Blue, Line[{{0, 0}, {1, 0}}]}, Line[{{0, 0}, {1, 1}}]}] will only have the horizontal line be blue. $\endgroup$ Commented May 24, 2015 at 4:28
  • $\begingroup$ Strongly related: (a/32717). $\endgroup$ Commented Sep 2, 2017 at 10:39

1 Answer 1

11
$\begingroup$

Here are two ways.

Using Dashing[None] to turn off dashing.

Graphics[{
   Dashed, Blue, Line[{{-9, 0}, {12, 0}}], 
   Dashing[None], Line[{{-9, -4}, {12, 4}}]}]

Using sub-lists to control the scope of directives.

Graphics[{
  Blue, 
   {Dashed, Line[{{-9, 0}, {12, 0}}]},
   Line[{{-9, -4}, {12, 4}}]}]

Both produce

lines

$\endgroup$
2
  • 3
    $\begingroup$ Also Dashing[{}] specifies that lines should be solid (from the docs) $\endgroup$ Commented May 24, 2015 at 4:36
  • $\begingroup$ Thank you. Am I the only one to be surprised that there's no Solid directive? Seems more logical than Dashing[None]... $\endgroup$ Commented Feb 20, 2023 at 10:30

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.