0
$\begingroup$

I have a somewhat complicated picture (actually two) to plot that I've been struggling with in Mathematica... the first one almost worked:

p1 = Plot3D[{x + y, x - y, -x + 2 y}, {x, -10, 10}, {y, -10, 10}, 
  PlotStyle -> {{Green, Opacity[0.5]}, {Yellow, Opacity[0.35]}, {Blue,
      Opacity[0.2]}}, Mesh -> None, Boxed -> False, Axes -> True, 
  BoxRatios -> {1, 1, 1}, AxesOrigin -> {0, 0, 0}, 
  AxesStyle -> Opacity[0]]
p2 = Graphics3D[{{Blue, Arrow[{{0, 0, 0}, {-10, 20, -10}}]}, {Red, 
    Arrow[{{0, 0, 0}, {10, 10, -10}}]}, {Blue, 
    Arrow[{{0, 0, 0}, {10, -10, -10}}]}}, BoxRatios -> {1, 1, 1}, 
  Axes -> False, AxesLabel -> {"x", "y", "z"}, 
  AxesStyle -> RGBColor[0, 0, 0], BaseStyle -> 12]
Show[p1, p2]

It is supposed to show three planes and their normal vectors at the origin, but they don't look perpendicular to the planes... is there a way to fix this?

The other picture is similar, but with the paraboloid y=|x|^2 instead of planes. I would like to plot three normal vectors at different points, but is there a way to do that without having to compute the vectors manually from the equation of the surface? Any inputs are welcome... :)

Edit: If one uses this code for the paraboloid (based on the answer given below), only one of the pieces shows up. Is there a fix for this?

w1 = Plot3D[x^2 + y^2, {x, -5, 5}, {y, -5, 5}, 
   PlotStyle -> {Green, Opacity[0.5]}, Mesh -> None, Boxed -> False, 
   Axes -> True, AxesOrigin -> {0, 0, 0}, AxesStyle -> Opacity[0], 
   BoxRatios -> Automatic];
w2 = Plot3D[x^2 + y^2, {x, 10, 15}, {y, 10, 15}, 
   PlotStyle -> {Green, Opacity[0.5]}, Mesh -> None, Boxed -> False, 
   Axes -> True, AxesOrigin -> {0, 0, 0}, AxesStyle -> Opacity[0], 
   BoxRatios -> Automatic];
Show[w1, w2]
$\endgroup$
4
  • 1
    $\begingroup$ Try using BoxRatios -> Automatic $\endgroup$ Jul 31, 2021 at 21:19
  • $\begingroup$ That works :) Thanks! $\endgroup$
    – ibr_
    Jul 31, 2021 at 23:03
  • $\begingroup$ Show[w1, w2, PlotRange -> All] for the new question. $\endgroup$
    – cvgmt
    Jul 31, 2021 at 23:53
  • $\begingroup$ Now it works, thanks! $\endgroup$
    – ibr_
    Aug 1, 2021 at 1:59

1 Answer 1

2
$\begingroup$

If you remove AxesStyle -> Opacity[0], you can see that the $z$ axis is shown from approximately -30 to 30. Therefore, the image is squeezed (because your forced the BoxRatios to be {1, 1, 1}), and that is why your normal vector do not look perpendicular (even though they are).

Solution 1

Use PlotRange -> {-10, 10} to fix the range of $z$ axis and then ClippingStyle -> None to remove the gray part outside the plotting range.

p1 = Plot3D[{x + y, x - y, -x + 2 y}, {x, -10, 10}, {y, -10, 10}, 
   PlotStyle -> {{Green, Opacity[0.5]}, {Yellow, 
      Opacity[0.35]}, {Blue, Opacity[0.2]}}, Mesh -> None, 
   Boxed -> False, Axes -> True, BoxRatios -> {1, 1, 1}, 
   AxesOrigin -> {0, 0, 0}, AxesStyle -> Opacity[0], 
   PlotRange -> {-10, 10}, ClippingStyle -> None];
p2 = Graphics3D[{{Blue, Arrow[{{0, 0, 0}, {-5, 10, -5}}]}, {Green, 
     Arrow[{{0, 0, 0}, {5, 5, -5}}]}, {Yellow, 
     Arrow[{{0, 0, 0}, {5, -5, -5}}]}}, BoxRatios -> {1, 1, 1}, 
   Axes -> False, AxesLabel -> {"x", "y", "z"}, 
   AxesStyle -> RGBColor[0, 0, 0], BaseStyle -> 12];
Show[p1, p2]

Mathematica graphics

Note: I have changed the colors of the arrows to match the planes and divided their length by 2, so that they all fit into your range (-10 to 10).

Solution 2

As mentioned by @Simon in the comments, you can also set BoxRatios -> Automatic. In this case, no clipping is needed and planes are displayed as tetragons.

p1 = Plot3D[{x + y, x - y, -x + 2 y}, {x, -10, 10}, {y, -10, 10}, 
   PlotStyle -> {{Green, Opacity[0.5]}, {Yellow, 
      Opacity[0.35]}, {Blue, Opacity[0.2]}}, Mesh -> None, 
   Boxed -> False, Axes -> True, AxesOrigin -> {0, 0, 0}, 
   AxesStyle -> Opacity[0], BoxRatios -> Automatic];
p2 = Graphics3D[{{Blue, Arrow[{{0, 0, 0}, {-5, 10, -5}}]}, {Green, 
     Arrow[{{0, 0, 0}, {5, 5, -5}}]}, {Yellow, 
     Arrow[{{0, 0, 0}, {5, -5, -5}}]}}, Axes -> False, 
   AxesLabel -> {"x", "y", "z"}, AxesStyle -> RGBColor[0, 0, 0], 
   BaseStyle -> 12];
Show[p1, p2]

Mathematica graphics

$\endgroup$
1
  • $\begingroup$ That works, thank you very much! I tried changing this code to draw the paraboloid picture one, but somehow only one of the pieces I'm plotting shows up. I edited my question above with the code I tried to run, based on your answer. $\endgroup$
    – ibr_
    Jul 31, 2021 at 22:26

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.