# How do I combine a piecewise function within a parametric plot?

I'm trying to combine two functions together piecewise style, but nest that within a ParametricPlot function. Here's my code right now:

xstrain1 = 1/72 Cos[q] (2 Cos[q/2] + 3 Sin[q])^2;
ystrain1 = 1/72 (3 + Csc[q/2])^2 Sin[q]^3;
xstrain2 = 1/2 Cos[q] Sin[q]^2;
ystrain2 = Sin[q]^3/2;

ParametricPlot[{{xstrain1, ystrain1}, {xstrain2, ystrain2}},
{q, 0,2*Pi}, PlotStyle -> {Blue, Red}]


and this is what it prints out: I need to combine the blue line with the orange line at the point of intersection, and I need to use the blue on the range of {0 < x<point of intersection} and then the red on the range of {point of intersection<x<2pi}. I'm trying to do something with nesting a ParametricPlot within a Piecewise function, but this may not be the best way to do this.

• Could you provide {{xstrain1, ystrain1}, {xstrain2, ystrain2}} - if not the exact form them a similar function that I can plot? – Sumit Apr 7 at 11:25
• xstrain1 = 1/72 Cos[[Theta]] (2 Cos[[Theta]/2] + 3 Sin[[Theta]])^2; ystrain1 = 1/72 (3 + Csc[[Theta]/2])^2 Sin[[Theta]]^3; xstrain2 = 1/2 Cos[[Theta]] Sin[[Theta]]^2; ystrain2 = Sin[[Theta]]^3/2; – orphanpunter69 Apr 7 at 11:32
• always give something we can copy paste, people are lazy here ;). – Sumit Apr 7 at 11:39

First thing you have to do is to find the interceptions. You can do that with NSolve

q0 = q /. NSolve[{xstrain1 == xstrain2, 0.01 < q < 2 Pi}, q]


{0.679674,1.5708,3.14159,4.71239,5.60351}

As you can see you need the first and last point.

q1 = q0[]
q2 = q0[]

x[q_] = Piecewise[{{xstrain1,  0 <= q <= q1},
{xstrain2, q1 <= q <= q2},
{xstrain1, q2 <= q <= 2 Pi}}];
y[q_] = Piecewise[{{ystrain1,  0 <= q <= q1},
{ystrain2, q1 <= q <= q2},
{ystrain1, q2 <= q <= 2 Pi}}];

ParametricPlot[{{xstrain1, ystrain1}, {xstrain2, ystrain2}, {x[q], y[q]}},
{q, 0, 2*Pi}, PlotStyle -> {Blue, Red, {Green, Dashed}}] 