1
$\begingroup$

Consider the polar coordinates function of a circle centered at $(2,0)$ with a radius of $\sqrt 2$:

$$\rho(\theta)=\left\{\quad \begin{array}{c} 2 \cos \theta +\sqrt{2-4 \sin ^2\theta} \\ 2 \cos \theta -\sqrt{2-4 \sin ^2\theta} \\ \end{array} \right.,\quad \theta\in[\dfrac{\pi}{4},\dfrac{\pi}{4}]$$

Visualization:

PolarPlot[{2 Cos[t] + Sqrt[2 - 4 Sin[t]^2], 
  2 Cos[t] - Sqrt[2 - 4 Sin[t]^2]}, {t, -Pi/4, Pi/4}, 
 PlotStyle -> {Red, Blue}, PlotRange -> {{0, 3.5}, {-1.5, 1.5}}, 
 Epilog -> {{PointSize -> .02, Point[{{1, 1}, {1, -1}}]}, {Green, 
    Dashed, Line[{{0, 1}, {1, 1}, {1, -1}, {0, -1}}]}, {Purple, 
    Line[{{1, 1}, {0, 0}, {1, -1}}]}}, AxesStyle -> Arrowheads[.03], 
 PlotRangePadding -> Scaled[.05], ImageSize -> 600]

enter image description here

Where the blue and red arcs represents different part of the piecewise defined circle.

However, in Mathematica, when expand the plot domain of $\theta$ to $[-\pi,\pi]$, either piecewise of it gives a whole circle:

p1 = PolarPlot[{2 Cos[t] + Sqrt[2 - 4 Sin[t]^2]}, {t, -Pi, Pi}, 
   PlotStyle -> {Red}, PlotRange -> {{0, 3.5}, {-1.5, 1.5}}, 
   Epilog -> {{PointSize -> .02, Point[{{1, 1}, {1, -1}}]}, {Green, 
      Dashed, Line[{{0, 1}, {1, 1}, {1, -1}, {0, -1}}]}, {Purple, 
      Line[{{1, 1}, {0, 0}, {1, -1}}]}}, AxesStyle -> Arrowheads[.03],
    PlotRangePadding -> Scaled[.05], ImageSize -> 400];
p2 = PolarPlot[{2 Cos[t] - Sqrt[2 - 4 Sin[t]^2]}, {t, -Pi, Pi}, 
   PlotStyle -> {Blue}, PlotRange -> {{0, 3.5}, {-1.5, 1.5}}, 
   Epilog -> {{PointSize -> .02, Point[{{1, 1}, {1, -1}}]}, {Green, 
      Dashed, Line[{{0, 1}, {1, 1}, {1, -1}, {0, -1}}]}, {Purple, 
      Line[{{1, 1}, {0, 0}, {1, -1}}]}}, AxesStyle -> Arrowheads[.03],
    PlotRangePadding -> Scaled[.05], ImageSize -> 400];
Grid[{{p1,p2}}]

What special technique has been used in Mathematica when handling complex values of the function? How to let Mathematica ignore those complex values (not to plot them)?

enter image description here

$\endgroup$
  • 2
    $\begingroup$ p1 = PolarPlot[{2 Cos[t] + Sqrt[2 - 4 Sin[t]^2]}, {t, -Pi, Pi}, RegionFunction -> ((2 - 4 Sin[#1]^2) > 0 &)] $\endgroup$ – Dr. belisarius Aug 27 '15 at 0:29
  • 1
    $\begingroup$ adding all those spurious options and code to a simple question makes it harder to read and understand. Please always try to post minimal examples $\endgroup$ – Dr. belisarius Aug 27 '15 at 0:31
  • $\begingroup$ Does wrapping the function in Re[...] not achieve what you want? Or using Piecewise? $\endgroup$ – N.J.Evans Aug 27 '15 at 1:07
  • $\begingroup$ thank you @belisarius. This is only a simple example. Another case may have similar issue: ContourPlot3D[ z == Sin[(x z - 1/2)^2 + 2 x y^2 - z/ 10] Exp[-(x - 1/2 - Exp[z - y])^2 + y^2 - z/5 + 3], {x, -1, 7}, {y, -2, 2}, {z, -1, 2}, PlotTheme -> "Classic"] $\endgroup$ – LCFactorization Aug 27 '15 at 1:10
4
$\begingroup$

Mathematica's special technique for handling complex values in a plot is to simply ignore them -- it plots nothing for at values of the domain for which the range is complex. Experiment with the following code.

Manipulate[
  PolarPlot[r[t], {t, min °, max °},
    PlotRange -> {{0, 3.5}, {-1.5, 1.5}},
    PlotRangePadding -> Scaled[.05],
    Epilog -> {
      Red, Line[{{0, 0}, r[min °] {Cos[min °], Sin[min °]}}],
      Blue, Line[{{0, 0}, r[max °] {Cos[max °], Sin[max °]}}]},
    ImageSize -> 400],
  {{min, -180}, -180, 0, 10, Appearance -> "Labeled"},
  {{max, 180}, .1, 180, 10, Appearance -> "Labeled"},
  {r, None},
  Initialization :> (r = (2 Cos[#] + Sqrt[2 - 4 Sin[#]^2] &))]

As you move the two sliders back and forth, you will see that the there are times when the radius vector of plot experiences discontinuities because it becomes complex-valued. There are dead zones (the background goes light red) in which nothing is plotted as the sliders are moved and pass through these zones.

Considering the OP's comment, I offer the following plot as a way of explaining how the full circle gets drawn.

Show @ 
  MapThread[
    PolarPlot[{2 Cos[t] + Sqrt[2 - 4 Sin[t]^2]}, Evaluate[#1],
      PlotStyle -> {CapForm["Butt"], Thickness[.05], #2},
      PlotRange -> {{0, 3.5}, {-1.5, 1.5}},
      PlotRangePadding -> Scaled[.05]] &, 
   {{{t, -π, -π/2}, {t, -π/4, 0}, {t, 0, π/4}, {t, π/2, π}}, 
    {Green, Blue, Red, RGBColor[9., .9, .6]}}]

circle

$\endgroup$
  • $\begingroup$ thank you! Don't know why, I got a lot error messages when changing the slider values. Another observation, both p1 and p2 above obtain whole circles. If complex variables were ignored, what we got should be only red or blue circular arc in the first figure above if my understanding is not wrong. $\endgroup$ – LCFactorization Aug 27 '15 at 23:59
  • $\begingroup$ @LCFactorization. I get no error message when moving the sliders in the above Manipulate expression. Did you copy from this answer correctly? As to your remark about p1 and p2, I am afraid you are wrong. My Manipulate should show you why. The full circle is drawn as four arcs: 0 < t < π/4, π/2 < t < π, -π < t < -π/2, -π/4 < t < 0, The arcs -π/2, < t < -π/4` and π/4 < t < π/2 are the dead zones where complex values are ignored. $\endgroup$ – m_goldberg Aug 28 '15 at 0:51
  • $\begingroup$ @LCFactorization. Your error messages come from your Epilog code. Graphics primitives don't tolerate complex values the way Plot does. $\endgroup$ – m_goldberg Aug 28 '15 at 1:52
  • $\begingroup$ thank you very much! I was confused by the two tangent lines of the circle. $\endgroup$ – LCFactorization Aug 28 '15 at 2:13
  • $\begingroup$ I tried this code Plot[{2 - 4 Sin[t]^2, 0}, {t, -Pi, Pi}, Ticks -> {(Range[10] - 5)/4 Pi, Automatic}, Filling -> {2 -> {{1}, {Yellow, White}}}] and it also separates real from complex regions clearly. $\endgroup$ – LCFactorization Aug 28 '15 at 2:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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