4
$\begingroup$

I can't figure how to draw a line with PolarPlot.

A vertical line through a is $r \cos(\theta) = a$, so

PolarPlot[a/Cos[theta], {theta, -Pi, Pi}]

works.

A horizontal line through b is $r \sin(\theta)=b$, so

PolarPlot[b/Sin[theta], {theta, -6, 6}] 

works. (Using {theta, -Pi, Pi} doesn't work because of dividing by $\sin(0)=0$ I guess.)

How do I draw a radial line with $\theta = \pi/3$? Should be a line with slope $\tan(\pi/3)$. Can it be done with PolarPlot? I guess not since you have to give a function of $r$.

$\endgroup$
6
  • 4
    $\begingroup$ Related question: "how do I draw the line $x=1$ using only Plot[]?" $\endgroup$ Commented Apr 29, 2013 at 3:59
  • $\begingroup$ You can't draw this exactly but you can define a tangent arc of arbitrarily large radius which passes through the origin at the angle you want. Try creating a circle with variable radius which you can get to cut through (0,0) and then increase the radius until it looks like you want it to. $\endgroup$ Commented Apr 29, 2013 at 5:11
  • 3
    $\begingroup$ Can't you just use Epilog for this goal? $\endgroup$ Commented Apr 29, 2013 at 5:45
  • $\begingroup$ Mathematica is madness. On paper I write theta = pi/4 (or whatever angle) to get an expression of a line in polar coordinates. But Mathematica needs 140 characters of code??? $\endgroup$ Commented Jan 19, 2018 at 3:52
  • 1
    $\begingroup$ Just add the Epilog->{Line@{{x0,y0},{x1,y1}} at the end of PolarPlot options list $\endgroup$
    – Rom38
    Commented Jan 19, 2018 at 4:52

5 Answers 5

7
$\begingroup$

You can use the option PolarGridLines to draw radial lines. For example:

PolarPlot[Cos[3 θ], {θ, 0, 2 π}, PolarGridLines->{{π/3},{}}]

enter image description here

$\endgroup$
6
$\begingroup$

My friend, what you ask for is madness. Assuming you're completely aware of just doing this, or similar:

Show[
 PolarPlot[{4/Cos[theta], 4/Sin[theta]}, {theta, -6, 6}],
 Graphics[Rotate[Line[500 {{-1, 0}, {1, 0}}], Pi/3]]]

enter image description here

Here's the most obvious brute-force mickey mouse approach:

PolarPlot[{4/Cos[theta], 4/Sin[theta], Evaluate[
   If[Pi/3 < theta < Pi/3 + 4/(2 Pi Abs[#]), #] & /@
    Range[-30, 30, .717]
   ]}, {theta, -6, 6}, PlotRange -> 40, PlotPoints -> 400,
 PlotStyle -> {{Thickness[.01]}, {Thickness[.01]}, Thickness[.01]}]

enter image description here

Exchanging some accuracy for performance:

PolarPlot[{4/Cos[theta], 4/Sin[theta],
  If[Pi/3 < theta < Pi/3 + .03, Range[-30, 30, .717]]
  }, {theta, -6, 6}, PlotRange -> 40, PlotPoints -> 400,
 PlotStyle -> {Thickness[.01], Thickness[.01], Thickness[.01]}]

enter image description here

I mention these to show how arbitrary your functions in Plots can be.

Here's one implementation of @Jonathan's idea:

PolarPlot[{4/Cos[theta], 4/Sin[theta], .2/(theta - Pi/3)},
 {theta, -2.1 Pi, 2.1 Pi}, PlotRange -> 40]

enter image description here

Another, flakier version:

PolarPlot[{4/Cos[theta], 4/Sin[theta], 10000 (theta - Pi/3)},
 {theta, -2.1 Pi, 2.1 Pi}, PlotRange -> 40]

enter image description here

$\endgroup$
2
$\begingroup$

Adding a straight line to a PolarPlot. To convert PolarPlot[r[θ],{θ,a,b}] to ParametricPlot use Parametric[r[θ]*Cos[θ],r[θ]*Sin[θ], then add your line.

Method 1: Just use parametric plot instead. Line is θ - Pi/3.

scalingFact = 5;
pPa = ParametricPlot[
  {{Sin[3 t] Cos[t], Sin[3 t] Sin[t]}, {Cos[Pi/3]*t, Sin[Pi/3]*t}/scalingFact}, {t, 0, Pi}, 
  PlotLabel -> "Parametric", ImageSize -> Tiny
]

Method 2: PolarPlot then ParametricPlot with line and Show both.

pPo = PolarPlot[{Red, Sin[3 t]}, {t, 0, Pi}, Mesh -> 10, 
 PlotLabel -> "Polar", ImageSize -> Tiny];

pPa = ParametricPlot[{Cos[Pi/3]*t, Sin[Pi/3]*t}/scalingFact, {t, 0, Pi}, 
 ImageSize -> Tiny];

Show[pPo, pPa, PlotStyle -> {{Red}, {Green}}]
$\endgroup$
2
  • $\begingroup$ my apologies obviously I am having trouble with this unusual editor. Could someone point me to some directions or a tutorial on how to input comments and code into this site properly. Thankyou $\endgroup$ Commented May 25, 2018 at 6:07
  • $\begingroup$ mathematica.stackexchange.com/editing-help $\endgroup$
    – Kuba
    Commented May 25, 2018 at 6:24
2
$\begingroup$

For lines that do not pass through the origin you can use the first argument of PolarPlot as follows:

PolarPlot[{4/Sin[theta], 4/Cos[theta], 10/(Sin[theta] + Cos[theta]), 
  10/(Sin[theta] - Cos[theta]), 20/(Sin[theta] + 3 Cos[theta])}, {theta, -3, 3}, 
 PlotRange -> {{-20, 20}, {-20, 20}}, PlotLegends -> "Expressions"]

enter image description here

To add lines that pass through the origin you can use Epilog as suggested by Rom38 in a comment or PolarGridLines as in Carl's answer.

$\endgroup$
0
2
$\begingroup$

Just to show some "new" functions (as of 2014/2015, so new since the original post):

PolarPlot[Sin[3  \[Theta]], {\[Theta], 0, 2  \[Pi]}
 , Epilog -> {
   With[{\[Theta] = Pi/3}, (* just to "show" the equation *)
    HalfLine[{0, 0}, FromPolarCoordinates[{1, \[Theta]}]]],
   InfiniteLine[
    FromPolarCoordinates /@ 
     Values@FindInstance[
       r  Sin[\[Theta]] == 0.7 && 
        r > 0 && -Pi <= \[Theta] < Pi, {r, \[Theta]}, Reals, 2]
    ],
   InfiniteLine[
    FromPolarCoordinates /@ 
     Values@FindInstance[
       r  Cos[\[Theta]] == 0.7 && 
        r > 0 && -Pi <= \[Theta] < Pi, {r, \[Theta]}, Reals, 2]
    ]
   },
 PlotRange -> 1.02]

enter image description here

$\endgroup$

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