# Plot part of a circle

I want to draw a path of integration and I am facing the following problem.

Given 2 point on the unit circle, draw all point of the circle that are left of the line the two points define. This is to imply that the points are not horizontal.

I have a crude solution for that in which I define a function in which I give the 2 points and a point on the circle and it returns it if it is to be drawn.

However this solution is particularly ugly and I am wondering if there is a more elegant one.

EDIT:

I solved my problem using RegionFunction. For example

P1 = {Sqrt[2]/2, Sqrt[2]/2};
P2 = {1/2, -(Sqrt[3]/2)};
dif = P1 - P2;
norm = {x, y} /. Solve[dif.{x, y} == 0, {x, y}][[1]] /. {x -> 1, y -> 1} // N

Show[
ContourPlot[x^2 + y^2 == 1, {x, -1, 1}, {y, -1, 1},
RegionFunction ->
Function[{x,
y}, (y - P1[[2]]) (P2[[1]] - P1[[1]]) - (x - P1[[1]]) (P2[[2]] -
P1[[2]]) <= 0]],
Graphics[{PointSize[0.008], Point[{P1, P2}]}],
PlotRange -> {{-1, 1}, {-1, 1}}]

• Please show your code, as it helps us help you. Commented Oct 14, 2014 at 0:13

I think you are looking for the following.

plotPointCircle[f_, s_, d_: counterclockwise] :=
Module[{a = ArcTan @@ f, b = ArcTan @@ s},
{a, b} = If[d === counterclockwise, If[a < b, {a, b}, {a, b + 2 Pi}],
If[a < b, {b, a + 2 Pi}, {b, a}]];
ParametricPlot[{Cos[t], Sin[t]}, {t, a, b},
PlotRange -> {{-1.2, 1.2}, {-1.2, 1.2}},
Epilog -> {Red, PointSize[Large], Point[{f, s}]}]
]

pts = Normalize /@ RandomReal[{-1, 1}, {2, 2}]
plotPointCircle @@ pts


Update

This is your example.

P1 = {Sqrt[2]/2, Sqrt[2]/2};
P2 = {1/2, -(Sqrt[3]/2)};
Grid[{{plotPointCircle[P1, P2], plotPointCircle[P1, P2, clockwise]}}]


You can also use Circle:

p1 = {Sqrt[2]/2, Sqrt[2]/2};
p2 = {1/2, -(Sqrt[3]/2)};
f[pa_, pb_, b_, opts : OptionsPattern[Plot]] :=
Graphics[{Circle[{0, 0},
1, {#1, #2 + 2 b Pi} & @@ (ArcTan @@@ {pa, pb})], Red,
PointSize[0.04], Point[{pa, pb}]}, Axes -> True,
AspectRatio -> Automatic, AxesOrigin -> {0, 0}, opts]


where b is 0 for clockwise path and 1 for counterclockwise:

Row[Framed@
f[p1, p2, #, PlotRange -> Table[{-1.2, 1.2}, {2}],
ImageSize -> 300] & /@ {0, 1}]


For plotting circles more natural use polar coordinate system:

P1 = {Sqrt[2]/2, Sqrt[2]/2};
P2 = {-1, 0};
theta1 = ArcTan @@ P1;
theta2 = ArcTan @@ P2;
PolarPlot[1, {r, theta2, theta1},
PlotRange -> {{-1.2, 1.2}, {-1.2, 1.2}},
Epilog -> {Red, PointSize[Large], Point[{P1, P2}]}]


PS: PolarPlot[1, {r, theta2, theta1}] and PolarPlot[1, {r, theta1, theta2}] are the same