Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

ParametricPlot3D vs Reduce

31 views
Skip to first unread message

Andrzej Kozlowski

unread,
Jan 7, 2012, 5:22:43 AM1/7/12
to
I just came across something somewhat baffling, though it could be the
result of an imperfect understanding of how 3D graphic functions work.
Consider the following three rational functions of two variables, which
we will think of as parameters of a point on a surface in 3D.

rats = {(-b - 2*d - b^3*d^2)/(b*d), (2*b + d + b^4*d +
2*b^3*d^2)/(b^2*d), (-1 - 2*b^3*d - b^2*d^2)/(b^2*d)};

Now, note that:

Reduce[Thread[-1 <= rats <= 1], {b, d}]

False

in other words, there are no values of the parameters b and d for which
the point lies in the unit cube. However:

ParametricPlot3D[rats, {b, -10, 10}, {d, -10, 10},
PlotRange -> {{-1, 1}, {-1, 1}, {-1, 1}},
AxesLabel -> {"a", "b", "c"}]

There appear to be several polygons inside the unit cube that should not
be there?

Andrzej Kozlowski



Andrzej Kozlowski

unread,
Jan 7, 2012, 5:28:19 AM1/7/12
to
On the other hand this works fine:

ParametricPlot3D[rats, {b, -10, 10}, {d, -10, 10},
RegionFunction ->
Function[{x, y, z, u,
v}, -1 <= x <= 1 && -1 <= y <= 1 && -1 <= z <= 1],
AxesLabel -> {"a", "b", "c"}]

The surface becomes visible in a somewhat larger cube:

ParametricPlot3D[rats, {b, -10, 10}, {d, -10, 10},
RegionFunction ->
Function[{x, y, z, u,
v}, -3 <= x <= 3 && -3 <= y <= 3 && -3 <= z <= 3],
AxesLabel -> {"a", "b", "c"}]

So the polygons in the earlier picture (with PlotRange restricted to the
unit cube) must be due to some artifact of the way ParametricPlot3D
displays a surface. Possibly a bug?

Andrzej Kozlowski

Bob Hanlon

unread,
Jan 8, 2012, 4:24:51 AM1/8/12
to
rats = {(-b - 2*d - b^3*d^2)/(b*d),
(2*b + d + b^4*d + 2*b^3*d^2)/(b^2*d),
(-1 - 2*b^3*d - b^2*d^2)/(b^2*d)};

ParametricPlot3D does not plot the intersection of {fx, fy, fz}. For
the intersection use

Plot3D[1, {b, -10, 10}, {d, -10, 10},
RegionFunction ->
Function[{b, d, z}, And @@ Thread[-1 <= rats <= 1]]]

RegionPlot[And @@ Thread[-1 <= rats <= 1],
{b, -10, 10}, {d, -10, 10}]

As expected, the results are empty. However, applying only two of the conditions

Plot3D[1, {b, -10, 10}, {d, -10, 10},
RegionFunction ->

Function[{b, d, z}, And @@ Thread[-1 <= Drop[rats, #] <= 1]]] & /@
Range[3]

RegionPlot[And @@ Thread[-1 <= Drop[rats, #] <= 1],
{b, -10, 10}, {d, -10, 10}] & /@ Range[3]


Bob Hanlon

On Sat, Jan 7, 2012 at 5:20 AM, Andrzej Kozlowski <akozl...@gmail.com> wrote:
> I just came across something somewhat baffling, though it could be the
> result of an imperfect understanding of how 3D graphic functions work.
> Consider the following three rational functions of two variables, which
> we will think of as parameters of a point on a surface in 3D.
>
> rats = {(-b - 2*d - b^3*d^2)/(b*d), (2*b + d + b^4*d +
> 2*b^3*d^2)/(b^2*d), (-1 - 2*b^3*d - b^2*d^2)/(b^2*d)};
>
> Now, note that:
>
> Reduce[Thread[-1 <= rats <= 1], {b, d}]
>
> False
>
> in other words, there are no values of the parameters b and d for which
> the point lies in the unit cube. However:
>
> ParametricPlot3D[rats, {b, -10, 10}, {d, -10, 10},
> PlotRange -> {{-1, 1}, {-1, 1}, {-1, 1}},
> AxesLabel -> {"a", "b", "c"}]
>
> There appear to be several polygons inside the unit cube that should not
> be there?
>
> Andrzej Kozlowski
>
>
>



--
Bob Hanlon

Andrzej Kozlowski

unread,
Jan 8, 2012, 4:25:22 AM1/8/12
to
Well, I certianly did not mean to plot the region in the space with
coordinates {b,d,z} where the conditions are satisfied; what I wanted to
do was precisely what my code does: plot the part of the surface given
by these three parametric equations (rats) that lies inside the unit
cube. One way to do it is, as I pointed out in my second post:

ParametricPlot3D[rats, {b, -10, 10}, {d, -10, 10},
RegionFunction ->
Function[{x, y, z, u,
v}, -1 <= x <= 1 && -1 <= y <= 1 && -1 <= z <= 1],
AxesLabel -> {"a", "b", "c"}]

The reason why ParametricPlot3D[rats, {b, -10, 10}, {d, -10, 10},PlotRange->{{-1,1},{-1,1},{-1,1}}, AxesLabel -> {"a", "b", "c"}] shows some polygons was explained correctly by Heike Gramberg and Szabolcs Horvt; it is an artifact caused by the combination of three things:

1. The singularities of the parametric equations at b=0 and d=0.
2. The fact that Mathematica's plot functions by default connect points and regions on opposite sides of a singularity
3. The fact that restricting PlotRange caused ParametricPlot3D to construct a plot over a wider range than the one specified by PlotRange.

The combination of these three factors leads to the appearance of these spurious polygons. Once solution, as pointed out by both Heike and Szabolcs, is the use the Exclusions option but for my purpose RegionFunction is more suitable.

Andrzej

Andrzej Kozlowski

unread,
Jan 8, 2012, 4:21:48 AM1/8/12
to
Thanks. Now it's perfectly obvious and I think I should have seen it
myself (but didn't ;-) )

Andrzej


On 7 Jan 2012, at 12:37, Heike Gramberg wrote:

> You function is discontinuous at b=0 or d=0 where the
denominator becomes zero. The polygons you see are the result of
Mathematica connecting the points across this discontinuity (similar to
for example the vertical lines in Plot[Tan[x], {x, 0, Pi}]). To get rid
of these you need to specify Exclusions. In this example you could do
>
> ParametricPlot3D[rats, {b, -10, 10}, {d, -10, 10},
> AxesLabel -> {"a", "b", "c"},
> PlotRange -> {{-1, 1}, {-1, 1}, {-1, 1}}, Exclusions -> {b d = 0}]
>
> which will produce an empty box.
>
> Heike

Heike Gramberg

unread,
Jan 8, 2012, 4:21:17 AM1/8/12
to

Szabolcs Horvát

unread,
Jan 8, 2012, 4:33:01 AM1/8/12
to
Dear Andrzej,

It appears that rats is discontinuous around 0:

Plot[rats /. b -> 1.2 // Evaluate, {d, -1, 1},
PlotStyle -> {{Red}, {Blue}, {Green}}, Axes -> False, Frame -> True]

It seems that both Plot and ParametricPlot3D are not able to detect this
discontinuity. What you see in the unit box is the same thing as the
vertical line at 0 in my Plot example above.

We can fix this by specifying the Exclusions option manually:

Plot[rats /. b -> 1.2 // Evaluate, {d, -1, 1},
PlotStyle -> {{Red}, {Blue}, {Green}}, Axes -> False, Frame -> True,
Exclusions -> {0}]

For ParemetricPlot3D, this is done as follows:

unitBox = {{-1, 1}, {-1, 1}, {-1, 1}}; (* avoid typing *)

ParametricPlot3D[rats, {b, -1, 1}, {d, -1, 1},
PlotRange -> 10 unitBox, MaxRecursion -> 2, PlotPoints -> 40,
Exclusions -> {b == 0, d == 0}]

If you change the plot range to 1 unitBox (instead of 10), you get an
empty plot.

Note that I needed to limit MaxRecursion and PlotPoints manually,
otherwise my machine would run out of memory and freeze due to disk
swapping...

Alternatively we can chop up the parameter range into four pieces by
hand, like this:

With[{pr = 10 unitBox},
Show[
ParametricPlot3D[rats, {b, 0, 1}, {d, 0, 1}, PlotRange -> pr],
ParametricPlot3D[rats, {b, -1, 0}, {d, 0, 1}, PlotRange -> pr],
ParametricPlot3D[rats, {b, 0, 1}, {d, -1, 0}, PlotRange -> pr],
ParametricPlot3D[rats, {b, -1, 0}, {d, -1, 0}, PlotRange -> pr]
]
]

--
Szabolcs Horvát
Mma QA site proposal: http://area51.stackexchange.com/proposals/37304

Andrzej Kozlowski

unread,
Jan 8, 2012, 4:33:32 AM1/8/12
to
Thanks a lot. As I mentioned in my second post on this subject, using RegionFunction also seems to deal with this problem:

ParametricPlot3D[rats, {b, -10, 10}, {d, -10, 10},
RegionFunction ->
Function[{x, y, z, u,
v}, -1 <= x <= 1 && -1 <= y <= 1 && -1 <= z <= 1],
AxesLabel -> {"a", "b", "c"}]

Andrzej


On 7 Jan 2012, at 14:05, Szabolcs Horv=E1t wrote:

> On 2012.01.07. 11:22, Andrzej Kozlowski wrote:
> Dear Andrzej,
>
> It appears that rats is discontinuous around 0:
>
> Plot[rats /. b -> 1.2 // Evaluate, {d, -1, 1},
> PlotStyle -> {{Red}, {Blue}, {Green}}, Axes -> False, Frame -> True]
>
> It seems that both Plot and ParametricPlot3D are not able to detect this discontinuity. What you see in the unit box is the same thing as the vertical line at 0 in my Plot example above.
>
> We can fix this by specifying the Exclusions option manually:
>
> Plot[rats /. b -> 1.2 // Evaluate, {d, -1, 1},
> PlotStyle -> {{Red}, {Blue}, {Green}}, Axes -> False, Frame -> True,
> Exclusions -> {0}]
>
> For ParemetricPlot3D, this is done as follows:
>
> unitBox = {{-1, 1}, {-1, 1}, {-1, 1}}; (* avoid typing *)
>
> ParametricPlot3D[rats, {b, -1, 1}, {d, -1, 1},
> PlotRange -> 10 unitBox, MaxRecursion -> 2, PlotPoints -> 40,
> Exclusions -> {b == 0, d == 0}]
>
> If you change the plot range to 1 unitBox (instead of 10), you get an empty plot.
>
> Note that I needed to limit MaxRecursion and PlotPoints manually, otherwise my machine would run out of memory and freeze due to disk swapping...
>
> Alternatively we can chop up the parameter range into four pieces by hand, like this:
>
> With[{pr = 10 unitBox},
> Show[
> ParametricPlot3D[rats, {b, 0, 1}, {d, 0, 1}, PlotRange -> pr],
> ParametricPlot3D[rats, {b, -1, 0}, {d, 0, 1}, PlotRange -> pr],
> ParametricPlot3D[rats, {b, 0, 1}, {d, -1, 0}, PlotRange -> pr],
> ParametricPlot3D[rats, {b, -1, 0}, {d, -1, 0}, PlotRange -> pr]
> ]
> ]
>
> --
> Szabolcs Horv=E1t

Szabolcs Horvát

unread,
Jan 8, 2012, 4:34:02 AM1/8/12
to
On 2012.01.07. 11:28, Andrzej Kozlowski wrote:
> On 6 Jan 2012, at 23:09, Andrzej Kozlowski wrote:
>
>> I just came across something somewhat baffling, though it could be the
> result of an imperfect understanding of how 3D graphic functions work.
> Consider the following three rational functions of two variables, which
> we will think of as parameters of a point on a surface in 3D.
>>
>> rats = {(-b - 2*d - b^3*d^2)/(b*d), (2*b + d + b^4*d +
>> 2*b^3*d^2)/(b^2*d), (-1 - 2*b^3*d - b^2*d^2)/(b^2*d)};
>>
>> Now, note that:
>>
>> Reduce[Thread[-1<= rats<= 1], {b, d}]
>>
>> False
>>
>> in other words, there are no values of the parameters b and d for
> which the point lies in the unit cube. However:
>>
>> ParametricPlot3D[rats, {b, -10, 10}, {d, -10, 10},
>> PlotRange -> {{-1, 1}, {-1, 1}, {-1, 1}},
>> AxesLabel -> {"a", "b", "c"}]
>>
>> There appear to be several polygons inside the unit cube that should
> not be there?
>>
>> Andrzej Kozlowski
>>
>>
>
> On the other hand this works fine:
>
> ParametricPlot3D[rats, {b, -10, 10}, {d, -10, 10},
> RegionFunction ->
> Function[{x, y, z, u,
> v}, -1<= x<= 1&& -1<= y<= 1&& -1<= z<= 1],
> AxesLabel -> {"a", "b", "c"}]
>
> The surface becomes visible in a somewhat larger cube:
>
> ParametricPlot3D[rats, {b, -10, 10}, {d, -10, 10},
> RegionFunction ->
> Function[{x, y, z, u,
> v}, -3<= x<= 3&& -3<= y<= 3&& -3<= z<= 3],
> AxesLabel -> {"a", "b", "c"}]
>
> So the polygons in the earlier picture (with PlotRange restricted to the
> unit cube) must be due to some artifact of the way ParametricPlot3D
> displays a surface. Possibly a bug?
>

I missed this message when I replied to the original one.

My understanding is that when you use a RegionFunction, all points
outside the region will be discarded before generating the 3D object for
the graphic.

When you use PlotRange, these points are kept when constructing the 3D
object, but the object is later clipped to the PlotRange before being
rendered.

It appears a workaround could be to specify a very large, but not
infinite plot region:

RegionFunction -> Function[{x, y, z}, x^2 + y^2 + z^2 < 1000]

The points outside this very large region could still contribute to some
parts of the graphic close to the origin, so you'll get a much more
beautiful plot if you do a "clean cut" using Exclusions.

I forgot to mention in my previous reply I reduce the (b,d) ranges to
(-1,1). Please change them back to (-10,10) to get the full plot.


--
Szabolcs Horvát
0 new messages