Group Abstract Group Abstract

Message Boards Message Boards

1
|
6.6K Views
|
11 Replies
|
6 Total Likes
View groups...
Share
Share this post:

Adding arrows in a smooth curve?

Posted 3 years ago

How to put arrows in a closed curve?

POSTED BY: Emy pena
11 Replies

Modifying the ContourPlot

It's a two-step process: (1) Determine the orientations of the lines produced by ContourPlot. (2) Replace the lines by arrows with the corrected orientations.

Start with the contour plot:

cplot = ContourPlot[{y^2 == 8 x, x == 2}, {x, -5, 5}, {y, -5, 5}, 
   AxesLabel -> {x, y}, AxesOrigin -> {0, 0}, 
   PlotLegends -> "Expressions", Axes -> True, AxesStyle -> Black, 
   Frame -> False];

It's probably unwise to predict (guess) how the lines will be oriented by ContourPlot. So first we replace the lines by arrows and see which point in the wrong direction:

orientation = {1, 1}; (* +1 = same, -1 = reverse *)
curvenumber = 0;
Normal@cplot /. Line[p_] :>
  {Arrowheads[orientation[[++curvenumber]] {0., 0.05, 0.05, 0.}], Arrow[p]}

The first (blue) path is oriented correctly; the second (gold) path needs to be reversed. We adjust orientation accordingly.

orientation = {1, -1}; (* +1 = same, -1 = reverse *)
curvenumber = 0;
Normal@cplot /. Line[p_] :>
  {Arrowheads[orientation[[++curvenumber]] {0., 0.05, 0.05, 0.}], Arrow[p]}

Because the OP mentioned Green's Theorem

RegionBoundary will construct a correctly oriented boundary. DiscretizeRegion approximates the region boundary and sometimes struggles with corners. It this case, it does a good job.

reg = ImplicitRegion[y^2/8 <= x <= 2, {x, y}];

Show[
  HighlightMesh[
   DiscretizeRegion[RegionBoundary[reg]], {Style[0, None]}],
  AbsoluteOptions@cplot /. 
   fb_FormBox :> HoldForm @@ MakeExpression[fb, StandardForm]] /. 
 Line[p_] :> {Arrowheads[{0., 0.04, 0.04, 0.04, 0.04, 0.04, 0.04}], 
   Arrow[Append[#, First@#] &@
     RotateLeft[p[[All, 2]], 4]]} (* in effect rotates arrow heads *)
POSTED BY: Michael Rogers
Posted 3 years ago

Thank you so much. Everything was really helpful.

POSTED BY: Emy pena
Posted 3 years ago

Where I can learn to do those codes?

POSTED BY: Emy pena
POSTED BY: Michael Rogers

Amelia,

I guess rather than ContourPlot you need/want ParametricPlot. If you want to do it in a clean way then you certainly should use Cianlucas package.

But just as a remark: In a "quick and dirty" way, the graphics can be tweaked simply like so:

pp = ParametricPlot[{{t^2, 8 t}/8, {2, -t}}, {t, -4, 4}, AxesLabel -> {x, y}, AxesOrigin -> {0, 0}, 
   PlotLegends -> {y^2 == 8 x, x == 2}, Axes -> True,  AxesStyle -> Black, Frame -> False, 
   PlotRange -> {{-1, 3}, Automatic}];
pp /. Line[pts__] :> {Arrowheads[{.1, #} & /@ Range[.1, 1, .1]], Arrow[pts]}

enter image description here

ADDENDUM: I missed that you want a counterclockwise version; here it is:

pp = ParametricPlot[{{t^2, -8 t}/8, {2, t}}, {t, -4, 4}, AxesLabel -> {x, y}, AxesOrigin -> {0, 0}, 
   PlotLegends -> {y^2 == 8 x, x == 2}, Axes -> True, AxesStyle -> Black, Frame -> False, 
   PlotRange -> {{-1, 3}, Automatic}];
pp /. Line[pts__] :> {Arrowheads[{.1, #} & /@ Range[.1, 1, .1]], Arrow[pts]}
POSTED BY: Henrik Schachner

My old package CurvesGraphics6 was motivated precisely by this kind of problems. You can download it from https://www.dimi.uniud.it/gorni/Mma

POSTED BY: Gianluca Gorni

I don't understand where Arrow[] is to appear. Are the arrows to be on the two lines? Up or down? Or are the arrows to point to something?

POSTED BY: Michael Rogers
Posted 3 years ago

The Arrows should show the orientation of the smooth closed curve and because I have to use Green Theorem, the orientation should be counterclockwise.

POSTED BY: Emy pena
Posted 3 years ago

enter image description here

POSTED BY: Emy pena

You can add the arrows (or anything else) using the Epilog and Prolog options.

POSTED BY: Gustavo Delfino
Posted 3 years ago

Sorry, I am new at using Mathematica. Could you give me more details, please?

POSTED BY: Emy pena
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard