4
$\begingroup$

When a plane in ContourPlot3D hits the boundary of you plot range it will be naturally cut of there. This will not always give pretty pictures.

For example here I get an irregular hexagon (what I don't want)

ContourPlot3D[{x1 + 2 x2 - 2 x3 == 0}, {x1, -1, 1}, {x2, -1, 
   1}, {x3, -1, 1}]

plot I don't want

here I get a rectangle (what I want)

ContourPlot3D[{x1 + 2 x2 - .1 x3 == 0}, {x1, -1, 1}, {x2, -1, 
  1}, {x3, -1, 1}] 

plot I want

How do I always get pretty rectangles even if my plane is oriented such that it hits the boundary of you plot range region in funny looking places?

Ideally, I would like to have an very easy option in ContourPlot3D, which does this automatically, since I will be doing lots of linear algebra plots which have solutions as intersecting planes. I would like to use ContourPlot, since this allows me to type in equations.

I have the latest Mathematica version and this will be used in an official publication and in my YouTube channel.

***** edit *****

I'm working in an affine space, where I want to invoke different inner products later on. So I do NOT like to use any normal vectors or anything that assumes perpendicularity, length, angle or an inner product. In that way I can really authentically communicate mathematics through Mathematica.

$\endgroup$
6
  • $\begingroup$ It happens even if you use primitives precisely due to clipping: Graphics3D[Hyperplane[{1, 2, -2}, 0], PlotRange -> 1] So, you're looking for a plot range where the plane looks rectangular? $\endgroup$ Feb 11, 2021 at 14:29
  • $\begingroup$ So your'e not looking to draw a plane, but rather a rectangle? You can use Graphics3D[Polygon[...]] and calculate 4 points on your plane that form the edges of your rectangle. $\endgroup$ Feb 11, 2021 at 14:55
  • $\begingroup$ I do not like to draw a rectangle, I would like to check a mathematical equation. To see if points lie on a plane, or planes meet in a point. So it is about displaying linear equations. Now these equations I would like to look like pretty planes, if possible. $\endgroup$ Feb 11, 2021 at 17:56
  • $\begingroup$ @ennui, I want that the planes look like pretty planes in a given plot range. So I'm not looking for a plot range. I would like mathematica to truncate the plane earlier to get the largest rectangle possible in that plot range for example (Although a smaller one, or scalable rectangle is fine too). $\endgroup$ Feb 11, 2021 at 18:01
  • $\begingroup$ "pretty" is subjective, so you'd need to somehow make a concrete criterion out of "pretty". $\endgroup$ Feb 12, 2021 at 0:34

2 Answers 2

4
$\begingroup$

To prevent clipping at the top and bottom:

1. You can set the x3 range to cover the minimum and maximum values of x3 under the constraints given by the first argument and the ranges of x1 and x2:

{zmin, zmax} = Through[{NMinValue, NMaxValue}[{x3, 
  x1 + 2 x2 - 2 x3 == 0 && -1 <= x1 <= 1 && -1 <= x2 <= 1}, {x1, x2, x3}]]
{-1.5, 1.5}
ContourPlot3D[{x1 + 2 x2 - 2 x3 == 0}, {x1, -1, 1}, {x2, -1, 1}, {x3, zmin, zmax}]

enter image description here

2. You can also use ImplicitRegion or ParametricRegion:

impreg = ImplicitRegion[{x1 + 2 x2 - 2 x3 == 0 && -1 <= x1 <= 1 && -1 <= x2 <= 1},
  {x1, x2, x3}]
ImplicitRegion[x1 + 2 x2 - 2 x3 == 0 && -1 <= x1 <= 1 && -1 <= x2 <= 1,  
 {x1, x2, x3}]

You can use impreg with RegionPlot3D:

RegionPlot3D[DiscretizeRegion[impreg], Mesh -> Automatic, Axes -> True]

enter image description here

Alternatively, you can use CoordinateBounds @ impreg to get the variable limits and use them with ContourPlot3D:

vlims = Sequence @@ MapThread[Prepend[#]@#2 &] @
   {{x1, x2, x3}, CoordinateBounds @ impreg};

ContourPlot3D[x1 + 2 x2 - 2 x3 == 0, Evaluate[vlims], Axes -> True]

enter image description here

parreg = ParametricRegion[{{x1, x2, x3}, 
  x1 + 2 x2 - 2 x3 == 0 && -1 <= x1 <= 1 && -1 <= x2 <= 1}, {x1, x2, x3}]

RegionPlot3D[DiscretizeRegion[parreg], Mesh -> Automatic, Axes -> True]
same picture
$\endgroup$
3
  • $\begingroup$ I was hoping there was an easy build-in function for this. Is there ? $\endgroup$ Feb 11, 2021 at 19:57
  • $\begingroup$ One could also use e.g. LinearOptimization[x3, {x1 + 2 x2 - 2 x3 == 0 && -1 <= x1 <= 1 && -1 <= x2 <= 1}, {x1, x2, x3}] $\endgroup$ Feb 12, 2021 at 0:41
  • $\begingroup$ @ChrisDjango, try also ImplicitRegion/ParametricRegion $\endgroup$
    – kglr
    Feb 12, 2021 at 1:11
3
$\begingroup$

Edit

@Chris Django

This equation $a x_1 + b x_2 + c x_3=0$ is in an Orthogonal space $\mathrm{R}^3$, so it is equivalent to $(a,b,c)\cdot (x_1,x_2,x_3)=0$,it means that $(x_1,x_2,x_3)$ lies in the complement orthogonal space about the normal vector $(a,b,c)$,that is why we introduce the HodgeDual since all the $(x_1,x_2,x_3)$ is belong to a linear space which span by the vectors of HodgeDual. If you want to affine space, the equation need to rewrite to depend on some bases such as $e_1,e_2,\cdots$,not the form $a x_1 + b x_2 + c x_3=0$

Original

It is easy to do this by ParametricPlot3D instead of ContourPlot3D

normal = RandomReal[{-10, 10}, 3]
{v1, v2, v3} = HodgeDual[normal];
{e1, e2, e3} = Orthogonalize[{v1, v2, v3}];
ParametricPlot3D[{0, 0, 0} + u*e1 + v*e2, {u, -1, 1}, {v, -1, 1}, 
 BoundaryStyle -> {Thick, Blue}, Mesh -> None]
$\endgroup$
11
  • 1
    $\begingroup$ I was wondering how your answer encodes the algebraic linear equation in an affine space or did you tacitly invoke an inner product somewhere in your hodge and orthogonalize operations ? $\endgroup$ Feb 11, 2021 at 18:15
  • 2
    $\begingroup$ @ChrisDjango Your equation is not in an affine space since all of them are use the base {1,0,0},{0,1,0},{0,0,1}. BTW, you want rectangle instead of Parallelogram,so here we use Orthogonalize $\endgroup$
    – cvgmt
    Feb 12, 2021 at 2:04
  • $\begingroup$ The base {1,0,0},{0,1,0},{0,0,1} can be the base of an affine space, as long as you don't define an inner product. So the space is affine. Pretty sure about that. $\endgroup$ Feb 12, 2021 at 8:48
  • $\begingroup$ @ChrisDjango But Mathematica use build-in {1,0,0},{0,1,0},{0,0,1} and orthogonal space.in graphics such as ContourPlot3D or other graphics function. $\endgroup$
    – cvgmt
    Feb 12, 2021 at 8:53
  • $\begingroup$ This answer is not correct. You assume an inner product, instead of a mathematical paring. You could have also used the relativistic inner product. For examplen (a,b,c) \cdot_r (x1,x2, - x3) = a x1+ bx2 +c x 3, where (x1,x2, x3) \cdot_r (x1,x2, x3) = - x^2 + x2^2 + x^3. Your answer is not mathematically sound. $\endgroup$ Feb 12, 2021 at 9:01

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.