2
$\begingroup$

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}}]
$\endgroup$
1
  • 1
    $\begingroup$ Please show your code, as it helps us help you. $\endgroup$ Commented Oct 14, 2014 at 0:13

3 Answers 3

2
$\begingroup$

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

Blockquote

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]}}]

Blockquote

$\endgroup$
4
$\begingroup$

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}]

enter image description here

$\endgroup$
0
$\begingroup$

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}]}]

enter image description here

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

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.