# How to combine regions of two 3D plots

I need to combine two plots like this Combining two plots which are in two regions but in 3D case. The problem is that I don't know where exactly boundary passes.

I have two complex functions qpC32 and qpC34. And I want to plot only real parts of this functions in such a way that

Where Im@qpC32 != 0 do qpC32=0 && Plot[Re@qpC32, {q, 0, 2000}, {m5, 0, 2000}]
Where Im@qpC34 != 0 do qpC34=0 && Plot[Re@qpC34, {q, 0, 2000}, {m5, 0, 2000}]


and after that I want to combine two plots:

Plot[Re@qpC32+Re@qpC34, {q, 0, 2000}, {m5, 0, 2000}]


It is not correct code but it is a general idea what I want to do.

And it is what I want And finally here is my code for my functions and plotting theirs.

eqn = j -
Sqrt[q^2 + qp^2 -
2 q qp Cos[\[Theta]]] - \[Sqrt](qp^2 +
1/2 (16 m5^2 + ma^2 + mp^2 -
Sqrt[(-(16 m5^2) - ma^2 - mp^2)^2 -
4 (ma^2 mp^2 - 16 m5^2 qp^2)])) == 0;
With[{gensol = Solve[eqn , qp]},
Block[{\[Theta] = Pi/12, m = 5.5, M = 300, Nc = 3, c = \!$$\* TagBox[ InterpretationBox[ RowBox[{"\"\<-4.46874\>\"", "*", SuperscriptBox["10", "\"\<4\>\""]}], -44687.3983417778, AutoDelete->True], ScientificForm]$$, b = \!$$\* TagBox[ InterpretationBox[ RowBox[{"\"\<1.61594\>\"", "*", SuperscriptBox["10", "\"\<5\>\""]}], 161593.81818181818, AutoDelete->True], ScientificForm]$$, k1 = \!$$\* TagBox[ InterpretationBox[ RowBox[{"\"\<1.6485\>\"", "*", SuperscriptBox["10", "\"\<1\>\""]}], 16.485010961790245, AutoDelete->True], ScientificForm]$$, k2 = \!$$\* TagBox[ InterpretationBox[ RowBox[{"\"\<-1.31313\>\"", "*", SuperscriptBox["10", "\"\<1\>\""]}], -13.131344420001051, AutoDelete->True], ScientificForm]$$, ma, mp,
j},(*subs vals when gensol is evaluated*){j = \[Sqrt](q^2 +
1/2 (16 m5^2 + ma^2 + mp^2 +
Sqrt[(-(16 m5^2) - ma^2 - mp^2)^2 -
4 (ma^2 mp^2 - 16 m5^2 q^2)])),
ma = \[Sqrt](-2 (M^2 -
2 (3 k1 + k2) (Sqrt[(c + M^2 + 2 m5^2)/(2 (k1 + k2))] +
m b/(2 (c + M^2 + 2 m5^2)))^2 - c + 2 m5^2)),
mp = Sqrt[
2 b m (Sqrt[(c + M^2 + 2 m5^2)/(2 (k1 + k2))] +
m b/(2 (c + M^2 + 2 m5^2)))^-1]};
sols = gensol]];
qpC32 = Compile[{{q, _Complex}, {m5, _Complex}},
Evaluate[qp /. sols[]],
RuntimeOptions -> "EvaluateSymbolically" -> False] ;
qpC34 = Compile[{{q, _Complex}, {m5, _Complex}},
Evaluate[qp /. sols[]],
RuntimeOptions -> "EvaluateSymbolically" -> False] ;
Plot3D[ Re@qpC34[q, m5], {q, 0, 2000}, {m5, 0, 2000},
PlotRange -> Full]
Plot3D[ Im@qpC34[q, m5], {q, 0, 2000}, {m5, 0, 2000},
PlotRange -> Full]
Plot3D[ Re@qpC32[q, m5], {q, 0, 2000}, {m5, 0, 2000},
PlotRange -> Full]
Plot3D[ Im@qpC32[q, m5], {q, 0, 2000}, {m5, 0, 2000},
PlotRange -> Full]


You can use option RegionFunction in Plot3D to restrict the part that's plotted. First we'll create RegionFunctions for each of the plots, and apply them to create the individual plots:

rg32 = Function[{q, m5}, Chop[Im[qpC32[q, m5]]] == 0];
rg34 = Function[{q, m5}, Chop[Im[qpC34[q, m5]]] == 0];
plt32 = Plot3D[Re@qpC32[q, m5], {q, 0, 2000}, {m5, 0, 2000}, RegionFunction -> rg32];
plt34 = Plot3D[Re@qpC34[q, m5], {q, 0, 2000}, {m5, 0, 2000}, RegionFunction -> rg34];


Here I get some warnings about infinities. It's okay; Mathematica says it will proceed without compiling the region functions. In this case, it doesn't affect the plots.

Then we show both plots together with Show[plt34,plt32] I chose plt34 first in Show, because the first plot in Show determines the plot range, and plt34's range encompasses that of plt32. In general, if you want to make sure you get the full plot range, then you need to specify the plot range for each constituent plot (plt32 and plt34) explicitly with PlotRange`.