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 *)