How to do a line integral visually in version 10 or later

In version 10, Mathematica introduces some Region functions, which allow us to do integrals very visually. We can do this even if we don't know any Mathematica syntax and it can help me show others that don't use this software. I can do any integral use these two steps:

• Plot the function, show the region to integral

ContourPlot[{E^x == y, y == 2, x == 0}, {x, -3, 3}, {y, -3, 3},
PlotLegends -> "Expressions"]


• Make an ImplicitRegion to integral and do calculation

region = ImplicitRegion[Reduce[{y > E^x, x > 0, y < 2}], {x, y}];
NIntegrate[E^(x y)/(y^y - 1), Element[{x, y}, region]]


Additionally, we can do it in textbook form directly like:

This is very intuitive to show.

Question

How can we use this region feature do line integrals? Such as the vector field is {y, x}. The region is RegionUnion[Circle[{0,0},1,{0,45°}],Line[{{0,0},{1,0}}]] The move direction is from $O\to A\to B$ as follows:

Show[VectorPlot[{y, x}, {x, -1, 1}, {y, -1, 1}],
Graphics[{Thick, Circle[{0, 0}, 1, {0, 45°}],
Arrow[{{0, 0}, {1, 0}}], Style[Text["A", {.9, -.1}], 20, Red],
Style[Text["B", {Sqrt[2]/2, .8}], 20, Red]}], AxesOrigin -> {0, 0},
Axes -> True, Frame -> False, Ticks -> None]


As I know, the result is $\frac{1}{2}$.

Or caculate the line integral in a close path, region is RegionUnion[Circle[{0,0},1,{0,45°}],Line[{{0,0},{1,0}}],Line[{{Sqrt[2]/2,Sqrt[2]/2},{0,0}}]],its direction is from $O\to A\to B\to O$:

Show[VectorPlot[{y, x}, {x, -1, 1}, {y, -1, 1}],
Graphics[{Thick, Circle[{0, 0}, 1, {0, 45 °}],
Arrow[{{0, 0}, {1, 0}}], Arrow[{{Sqrt[2]/2, Sqrt[2]/2}, {0, 0}}],
Style[Text["A", {.9, -.1}], 20, Red],
Style[Text["B", {Sqrt[2]/2, .8}], 20, Red]}], AxesOrigin -> {0, 0},
Axes -> True, Frame -> False, Ticks -> None]


As I know, the result is $0$. Of course, this vector field {y,x} is very simple so that you can see the result just by a glance, but this is just an example. I want know the general method.

• The word "visually" and using *Region* functions mean different things to me, but one obstacle to the latter is that regions are not oriented. E.g., the mesh elements in DiscretizeRegion[RegionUnion[Circle[{0, 0}, 1, {0, Pi/4}], Line[{{1, 0}, {2, 0}}]]] do not have a consistent orientation. A solution will have to address orientation, as well as calculating tangents for the variety of possible regions and, if desired, recursive refinement of the mesh for whatever integration rules one wants. Not to mention singularity handling or other features of NIntegrate. A very big project. Oct 28, 2016 at 10:30

One way could be defining a proper parameter along the path.

Let's say you know the points on the path or equation of the path (Piecewise maybe).

pts = Join[{#, 0.} & /@ Range[0., 0.9, 0.1], {Cos[#], Sin[#]} & /@ Range[0., Pi/4, Pi/60],
# {Cos[Pi/4], Sin[Pi/4]} & /@ Range[.9, 0.0, -0.1]];


Define the path as a function of a single parameter

x[t_] = Interpolation[pts[[All, 1]]][t]
y[t_] = Interpolation[pts[[All, 2]]][t]
tmax = Length[pts]


According to this parameterisation

\begin{array}{ll} &t=1,tmax & O \\ &t=11 & A \\ &t=26 & B \end{array}

You can define individual sections as well. Now define the vector field and do the integration ($\int \vec{v}.\vec{dl}$)

vec[t_] = {y[t], x[t]}
dl[t_] = {D[x[t], t], D[y[t], t]}; (*Differential path element*)

NIntegrate[vec[t].dl[t], {t, 1, 26}] (*OAB*)
NIntegrate[vec[t].dl[t], {t, 26, tmax}](*BO*)
NIntegrate[vec[t].dl[t], {t, 1, tmax}](*OABO*)


0.5

-0.5

$-4.92228 \times 10^{-17}$

Show[VectorPlot[{y, x}, {x, 0, 1}, {y, 0, 1}],
Graphics[{Table[{Blue, Arrow[{{x[t], y[t]}, {x[t + 1], y[t + 1]}}],
Red, Arrow[{{x[t], y[t]}, {x[t], y[t]} + 0.2 vec[t]}]}, {t, 1, tmax - 1, 1}],
Table[Text[Style[t, 18, Bold], {x[t], y[t]}], {t, {1, 11, 26}}]}]]


parameterisation [t]

Here the parameter t is just the serial number of the points along the path. You can provide more points for better interpolation result in case of a curvy path. You can check it by

Graphics[{Gray, Arrowheads[{0, .05, .05, .05, 0.05}], Arrow[pts],
Black, Table[Text[t, {x[t], y[t]}], {t, tmax}]}]


316 is actually overlapping 1 and 36.

• What's meaning the dl？And why use vec[t].dl[t]?As I konw the integral result is 0.5 but not 9.5?
– yode
Oct 27, 2016 at 1:00
• Now it is the correct one (with explanation) :) Oct 27, 2016 at 8:35
• Wow,you did it. :)Can you show how do you get that $26$ or $11$?And would you think the region feature introduced in v10.0 would be helpful?
– yode
Oct 27, 2016 at 9:03
• I am not quite sure about Region. In principle, you can define the path as a region with a very tiny width and use the surface integration. I will check it later. Oct 27, 2016 at 11:36
• In this case,the region is RegionUnion[Circle[{0,0},1,{0,45°}], Line[{{0,0},{1,0}}]]
– yode
Oct 27, 2016 at 11:44