# How to divide the contour in three parts with the same arclength?

We set MeshFunctions to "ArcLength",but it is missing the boundary point,so there only two points on the contour.

con=ContourPlot[Cos[x] + Cos[y] == 1/2, {x, -Pi, Pi}, {y, -Pi, Pi},
MeshFunctions -> {0 &, "ArcLength"}, Mesh -> 2,
MeshStyle -> Directive[AbsolutePointSize, Red]] Although we can Cases the point from the contour,but it seems not so elegant.

## Updated

It seems that MeshShading does not work in ContourPlot. pts = Cases[Normal@con, Line[pts_] :> pts, -1];
ListPlot[pts, AspectRatio -> Automatic, Joined -> True,
MeshFunctions -> {"ArcLength"}, Mesh -> 2,
MeshStyle -> Directive[AbsolutePointSize, Red],
Epilog -> {Directive[AbsolutePointSize, Red],
Point@First@First@pts}, MeshShading -> ColorData /@ Range]

• herbertfederer, can you share how you came up with the spec {0 &, "ArcLength"} ? (I have never seen it before)
– kglr
Jun 5 at 16:38
• @kglr In the early version, for example, 11.3, we only need to use{"ArcLength"}. but something have been change since such version. Now we have to use two MeshFunction, it maybe a feature or maybe a bug. Jun 6 at 3:47

### 1. Specify Mesh as a list

ContourPlot[Cos[x] + Cos[y] == 1/2, {x, -Pi, Pi}, {y, -Pi, Pi},
MeshFunctions -> {0 &, ArcLength},
Mesh -> {Subdivide @ 3},
MeshStyle -> Directive[Red, PointSize@Large]] Note: Curiously, if we specify the setting for Mesh as a list of {mesh, style} pairs we can get rid of 0& in MeshFunctions:

ContourPlot[Cos[x] + Cos[y] == 1/2, {x, -Pi, Pi}, {y, -Pi, Pi},
MeshFunctions -> {ArcLength},
Mesh ->
{Thread[{Subdivide@3, Directive[ Red, Opacity, PointSize @.03]}]}]


same picture

### 2. Use DisplayFunction to add the missing point

ContourPlot[Cos[x] + Cos[y] == 1/2, {x, -Pi, Pi}, {y, -Pi, Pi},
MeshFunctions -> {0 &, ArcLength},
Mesh -> 2,
MeshStyle -> Directive[Red, PointSize @ Large],
DisplayFunction -> ReplaceAll[Point@x_ :> Point[Prepend@x]]] ### 3. Post-process to add the missing point

ReplaceAll[Point @ x_ :> Point[Prepend @ x]]@
ContourPlot[Cos[x] + Cos[y] == 1/2, {x, -Pi, Pi}, {y, -Pi, Pi},
MeshFunctions -> {0 &, ArcLength},
Mesh -> 2,
MeshStyle -> Directive[Red, PointSize@Large]] ### 4. Use MeshStyle to add the missing mesh point

ContourPlot[Cos[x] + Cos[y] == 1/2, {x, -Pi, Pi}, {y, -Pi, Pi},
MeshFunctions -> {0 &, ArcLength},
Mesh -> 2,
MeshStyle -> ({Red, PointSize @ Large, #, Point @ 1} &)] ## Update:

MeshShading is not an option for ContourPlot.

One way to get contours with multiple segments with different styles from ContourPlot is to extract the line coordinates and process them with a *Plot function that accepts MeshShading as an option (as done in the update in OP).

In the following, we wrap all Mesh* options (including MeshShading) in meshOptions and use ParametricPlot to process them to construct the desired graphics primitives and inject them in ContourPlot using a custom DisplayFunction:

ClearAll[meshOptions]

meshOptions[opts : OptionsPattern[]] :=
Module[{BSF = BSplineFunction[#]},
First[Show[ParametricPlot[BSF@t, {t, 0, 1}, opts],
Graphics[{MeshStyle /. FilterRules[{opts}, MeshStyle],
Point[BSF /@ {0, 1}]}]]]] &

meshOptions /: ContourPlot[a__, meshOptions[o___], b___] :=
ContourPlot[a, b,
DisplayFunction ->
ReplaceAll[Line[x_] :> (Dynamic @ meshOptions[o] @ x)] @* Normal]


Examples:

ContourPlot[Cos[x] + Cos[y] == 1/2, {x, -Pi, Pi}, {y, -Pi, Pi},
meshOptions[
MeshFunctions -> {"ArcLength"},
Mesh -> {Subdivide @ 3},
MeshStyle -> Directive[Red, AbsolutePointSize], ContourPlot[{Cos[x] + Cos[y] == 1/2, Cos[x] + Cos[y] == 1,
Sin[x] + Cos[y] == 1/2}, {x, -Pi, Pi}, {y, -Pi, Pi},
PlotLegends -> "Expressions",
meshOptions[
MeshFunctions -> {"ArcLength"},
Mesh -> {Subdivide @ 3},
MeshStyle -> Directive[CurrentValue @ "Color", AbsolutePointSize],
(Directive[CurrentValue @ "Color",  AbsoluteDashing[3 #]] & /@ Range)]] Add the option ContourStyle -> "Rainbow" to get • Thanks! I just found out that MeshShading cannot be used in ContourPlot, it is curious to me. See my updated. Jun 4 at 7:20
• MeshShading is not an option for ContourPlot. Please see the update for a hack to smuggle MeshShading option into ContourPlot.
– kglr
Jun 4 at 20:52
• @kglr Helpful interesting answer! I tried to understand the option MeshFunctions -> {0 &, ArcLength}: I changed the first part 0& arbitrarilly to 3&, but resulting plot doesn't change? Jun 5 at 9:07
• Ulrich, never seen this usage before.
– kglr
Jun 5 at 16:18

pt = Graphics[{Red, PointSize[Large], Point[{0, 0}]},
ImageSize -> 9];
con = Normal@
ContourPlot[Cos[x] + Cos[y] == 1/2, {x, -Pi, Pi}, {y, -Pi, Pi},
ContourStyle ->
Arrowheads[{0., {.1, Automatic, pt}, {.1, Automatic, pt}, {.1,
Automatic, pt}}]] /. Line -> Arrow You can also use the following, whose "points" scale with the size of the graphics.

pt = Graphics[{Red, Disk[]}];