TransWikia.com

Exclude a region in 3D plot

Mathematica Asked by PRI_YA on March 23, 2021

I need to exclude a region of $pi/3leq x leq 2 pi/3 $ and $pi/3leq y leq 2pi/3$
of this 3D plot:

Plot3D[Sin[x*y], {x, -Pi, Pi}, {y, -Pi, Pi}]

How to do it?

3 Answers

Plot3D[Sin[x y], {x, -Pi, Pi}, {y, -Pi, Pi}, 
 RegionFunction -> Function[{x, y, z}, Nor[Pi/3 <= x <= 2Pi/3, Pi/3 <= y <= 2Pi/3 ]]]

enter image description here

Also

ir = ImplicitRegion[{Nor[Pi/3 <= x <= 2Pi/3, Pi/3 <= y <= 2Pi/3 ]}, 
   {{x, -Pi, Pi}, {y, -Pi,  Pi}}];

Plot3D[Sin[x y], {x, y} ∈ ir]

same picture

Plot3D[Piecewise[{{Sin[x y], Nor[Pi/3 <= x <= 2 Pi/3, Pi/3 <= y <= 2 Pi/3]}}, 
  Undefined], {x, -Pi, Pi}, {y, -Pi, Pi}] 

same picture

 Plot3D[ConditionalExpression[Sin[x y], Nor[Pi/3 <= x <= 2 Pi/3, Pi/3 <= y <= 2 Pi/3]],
  {x, -Pi, Pi}, {y, -Pi, Pi}] 

same picture

Answered by kglr on March 23, 2021

An alternative to using RegionFunction is to use ConditionalExpression

Plot3D[
 ConditionalExpression[
  Sin[x*y], (x < Pi/3 || x > 2 Pi/3) && (y < Pi/3 || y > 2 Pi/3)], {x, -Pi, 
  Pi}, {y, -Pi, Pi}, AxesLabel -> Automatic]

enter image description here

Answered by Bob Hanlon on March 23, 2021

Other similar way.

f2[x_, y_] := 
 If[! (π/3 <= x <= (2 π)/3 || π/3 <= y <= (2 π)/3), 
  Sin[x*y], Undefined]
f3[x_, y_] := 
 Piecewise[{{Sin[
     x*y], ! (π/3 <= x <= (2 π)/3 || π/3 <= y <= (
        2 π)/3)}}, Undefined]
f4[x_, y_] := 
 Piecewise[{{None, (π/3 <= x <= (2 π)/3 || π/3 <= y <= (
       2 π)/3)}}, Sin[x*y]]

Answered by cvgmt on March 23, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP