0
$\begingroup$

I need to create two circles, where one circle is inside the other using the Piecewise function. So far I have

f[x_, y_, z_, a_] := Piecewise[{{1, x^2 + y^2 <= 30}, {0, x^2 + y^2 > 30},}

I know by changing the radius, I can have a circle inside the other, but how do I go about it using Piecewise?

$\endgroup$
  • 1
    $\begingroup$ What is $a$? What is $z$? Why use Piecewise? And do you want a Circle or a Disk? $\endgroup$ – David G. Stork Feb 10 '17 at 20:05
  • $\begingroup$ @IrisGarza How did you mean to apply Piecewise? $\endgroup$ – ercegovac Feb 10 '17 at 20:06
  • $\begingroup$ Why not use ParametricPlot, or if you need just two full circles, than simple Graphics directive. $\endgroup$ – ercegovac Feb 10 '17 at 20:08
5
$\begingroup$
PolarPlot[Piecewise[{{1, θ < 2 Pi}, {2, θ > 2 Pi}}], {θ, 0, 4 Pi}]

Module[{i = 1}, % /. x_Line :> {ColorData[3][i++], x}]

enter image description here

Also implicit curves can be given in a list:

ContourPlot[
 {x^2 + y^2 == 1, x^2 + y^2 == 2^2},
 {x, -E, E}, {y, -E, E},
]

enter image description here

$\endgroup$
2
$\begingroup$

It should be noted that constructing "chimeric" curves, given their implicit Cartesian equations, is not too hard, and does not need a piecewise construction. Recall that if $f(x,y)=0$ and $g(x,y)=0$ are two non-identical curves, then the curve $f(x,y)\,g(x,y)=0$ is a curve composed of the two other curves. Thus, using the Wizard's example:

ContourPlot[(x^2 + y^2 - 1) (x^2 + y^2 - 2^2) == 0, {x, -3, 3}, {y, -3, 3}]

two circles joined together

$\endgroup$
1
$\begingroup$
f[r1_, r2_] := Graphics[
  {Circle[{0, 0}, r1],
   Circle[{0, 0}, r2]}
  ]
$\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.