1
$\begingroup$

As the title indicates, I want to build (and manipulate) two three-dimensional surfaces in one bounding box, so that their intersection is highlighted and the unwanted parts of the surfaces are removed during their movement relative to each other.

First of all I created surface $x=0$ using ContourPlot3D. Here is the corresponding code (I used the right tool?):

cp1 = ContourPlot3D[x == 0, {x, -5, 5}, {y, -5, 5}, {z, -5, 5},
                    AxesLabel -> {"x", "y", "z"}]

which produces this output:

plane

Then I created surface $\cos (x) \sin (y)$ using Plot3D. Here is the corresponding code (I used the right tool?):

Plot3D[Cos[x]*Sin[y], {x, -5, 5}, {y, -5, 5}, AxesLabel -> {"x", "y", "z"}]

which produces this output:

surface

Then I created two three-dimensional surfaces ($\cos (x) \sin (y)$ and $x=0$) in one bounding box. Here is the corresponding code (I used the right tool?):

Show[cp1, Plot3D[Cos[x]*Sin[y], {x, -5, 5}, {y, -5, 5}, AxesLabel -> {"x", "y", "z"}]]

I get this output:

plane and surface

My question is the following: How can I move (manipulate) the surface $x=0$ along the $x$ axis (no movement along the $y$ and $z$ axes), so that surface $x=0$ would be cutoff surface for surface $\cos (x) \sin (y)$ and their intersection is highlighted. Surface $\cos (x) \sin (y)$ not moving.

If for example (this picture is taken not from Mathematics):

example

EDIT

@JM code is not working:

J. M.'s code

$\endgroup$
4
  • $\begingroup$ The code works in version 10 and 11. If you're using a version older than that, please edit your question to mention the version you are using. $\endgroup$ Commented Nov 11, 2017 at 1:06
  • $\begingroup$ @JM - I have the program "Mathematica 9" on my computer . Can I also put "Mathematica 11" on my computer? Can the two versions stand on the same computer? $\endgroup$
    – sasvak
    Commented Nov 12, 2017 at 14:23
  • $\begingroup$ @JM - I have 11.2 - it's working! I delete my 9 version , because Mathematica installer tell me about it! $\endgroup$
    – sasvak
    Commented Nov 12, 2017 at 17:35
  • $\begingroup$ sasvak, actually, it's possible to have more than one version of Mathematica on a computer. I personally do so to track changes between versions. $\endgroup$ Commented Nov 12, 2017 at 22:47

2 Answers 2

4
$\begingroup$

Here's a starting point:

n = 31;
Animate[Show[Plot3D[Cos[x] Sin[y], {x, -5, 5}, {y, -5, 5}, 
                    AxesLabel -> {"x", "y", "z"}, BoundaryStyle -> None, 
                    BoxRatios -> Automatic, Mesh -> {{xx}}, MeshFunctions -> {#1 &}, 
                    MeshStyle -> Directive[Red, Thick], PlotPoints -> 45, 
                    PlotRange -> {-5, 5}], 
             Graphics3D[InfinitePlane[{xx, 0, 0}, Rest[IdentityMatrix[3]]]]],
        {xx, -5, 5, 10/(n - 1)}]

slicing plane


For those working in older versions without InfinitePlane[], use the following instead:

Polygon[{Scaled[{0, 1, 1}, {xx, 0, 0}], Scaled[{0, -1, 1}, {xx, 0, 0}],
         Scaled[{0, -1, -1}, {xx, 0, 0}], Scaled[{0, 1, -1}, {xx, 0, 0}]}]

The technique is quite similar to what I used here.

$\endgroup$
6
  • $\begingroup$ @JM Hello! First of all thank you very much! But my Mathematica give me sign ------ orange "+" in right side -------- Message ---- "InfinitePlane is not a Graphics3D primitive or directive". $\endgroup$
    – sasvak
    Commented Nov 10, 2017 at 17:44
  • $\begingroup$ @JM And also surface $x=0$ not drawing, only intersection line is highlighted and moving $\endgroup$
    – sasvak
    Commented Nov 10, 2017 at 17:46
  • $\begingroup$ @JM Also moving sometimes hangs (or freeze) link $\endgroup$
    – sasvak
    Commented Nov 10, 2017 at 17:56
  • $\begingroup$ How did you save the animation? $\endgroup$
    – Raffaele
    Commented Nov 11, 2017 at 13:24
  • $\begingroup$ @Raffaele. what I actually do for exporting an animation is to use, well, Export[] + Table[]: Export["filename.gif", Table[(* stuff *)]] $\endgroup$ Commented Nov 11, 2017 at 13:48
1
$\begingroup$

Another way with interactivity, and animation:

Manipulate[
Show[
{
Plot3D[{Exp[- 0.09 (x^2 + y^2)] Cos[2 x] Sin[y]}, {x, -5, 5}, {y, -5, 5}, AxesLabel -> {"x", "y", "z"}, 
BoundaryStyle -> None, Mesh -> {{x0}}, 
MeshFunctions -> {#1 &}, 
MeshStyle -> Directive[Black, Thickness[0.01]], 
PlotRange -> {-1, 1}, 
PlotStyle -> {If[u, Opacity[0.8], Opacity[0]]}, 
PerformanceGoal -> "Quality", PlotTheme -> "Business"],

 Graphics3D[{EdgeForm[None], Yellow, 
 If[v, Directive[Opacity[0.8]], Directive[Opacity[0]]], 
 InfinitePlane[{x0, 0, 0}, {{0, 1, 0}, {0, 0, 1}}]}]
}, BoxRatios -> {1, 1, .9}
],
{{x0, -1.5}, -5, 5, 0.1, Appearance -> "Labeled"},
Delimiter,
{{u, True, "f[x]"}, {True, False}}, {{v, True, "Cut plane"}, {True, 
False}},
ControlPlacement -> Top
]

enter image description here

$\endgroup$
3
  • $\begingroup$ The code works in version 9? $\endgroup$
    – sasvak
    Commented Nov 12, 2017 at 15:12
  • $\begingroup$ @sasvak Sorry, I do not know. Just check it ! Anyway, it is possible that some functions regarding the appearance of the plot will belong to later updates if so, or substitute them with their equivalent. My suggestion is to eliminate them. If some important functions do not work, the code definitely is not for ver 9. Please, when ask a question, indicate the target version of MMA. $\endgroup$ Commented Nov 12, 2017 at 16:13
  • $\begingroup$ @JADN I have 11.2 - it's working! $\endgroup$
    – sasvak
    Commented Nov 12, 2017 at 17:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.