2
$\begingroup$

I'd like to show/draw only those curves within the circular region (highlighted in red), which corresponds to

a = 0 Degree, i.e., x^2+y^2<=1,

together with the red circle.

enter image description here

range1 = 80 Degree; incr = 10 Degree; range2 = 1.5;
longitude = Table[(x - Tan[a])^2 + 
 y^2 == (1/Cos[a])^2, {a, -range1, range1, incr}];

lattitude = Table[x^2 + (y - 1/(
    If[a > 0 Degree, 
      1, -1] Cos[a]))^2 == (Tan[a])^2, {a, -range1, range1, incr}];

tab = Flatten[{longitude, lattitude, x == 0, y == 0}];

ContourPlot[tab, {x, -range2, range2}, {y, -range2, range2}, ContourStyle -> Black]

I've tried

longitude = Table[Boole[x^2+y^2<=1]*((x - Tan[a])^2 + 
 y^2 == (1/Cos[a])^2), {a, -range1, range1, incr}];

But it doesn't work as I thought (the evaluation is very slow).

Any help is appreciated.

$\endgroup$
6
$\begingroup$

This is accomplished with RegionFunction:

ContourPlot[
 Evaluate[tab], {x, -range2, range2}, {y, -range2, range2},
 ContourStyle -> Black,
 RegionFunction -> (Norm[{#, #2}] < 1 &)
 ]

Output

$\endgroup$
1
  • $\begingroup$ Thank you very much. I didn't know this option before. $\endgroup$
    – Bemtevi77
    Aug 8 '17 at 21:59
1
$\begingroup$

An alternative to C. E.'s answer is to use the ability of ContourPlot[] to plot over a region, as in the following:

With[{range1 = 80 °, incr = 10 °},
     longitude = Table[(x - Tan[a])^2 + y^2 == Sec[a]^2,
                       {a, -range1, range1, incr}];
     latitude = Table[x^2 + (y - 1/((1 - 2 UnitStep[-a]) Cos[a]))^2 == Tan[a]^2,
                      {a, -range1, range1, incr}];
     ContourPlot[Flatten[{longitude, latitude, x == 0, y == 0}] // Evaluate,
                 {x, y} ∈ Disk[], ContourStyle -> Black]]
$\endgroup$

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.