Re: Why aren't both sides of a surface equally

• To: mathgroup at smc.vnet.net
• Subject: [mg81009] Re: [mg80974] Why aren't both sides of a surface equally
• From: Chris Hill <chill at wolfram.com>
• Date: Fri, 7 Sep 2007 02:15:21 -0400 (EDT)
• References: <200709060938.FAA15758@smc.vnet.net>

```At 04:38 AM 9/6/2007, David Park wrote:
>The following illustrates a strange behavior of surfaces with respect to
>opacity. The code draws a narrow cylinder with a red line on the inside of
>the cylinder and a black line on the outside of the cylinder. The cylinder
>is completely opaque. The inside red line does not show through the
>cylinder, which is proper behavior. However, the black outside line does
>show through the back face for a considerable range, which is certainly
>improper behavior.
>
>cylinder =
>   First[ParametricPlot3D[{5 Cos[\[Theta]1], 5 Sin[\[Theta]1],
>      z}, {\[Theta]1, 0, 2 \[Pi]}, {z, -1, 1},
>     PlotStyle -> {FaceForm[Orange, LightGray]},
>     PlotPoints -> {41, 5},
>     Mesh -> None]];
>
>outsideline =
>   First[ParametricPlot3D[{5.1 Cos[\[Theta]1], 5.1 Sin[\[Theta]1],
>      0.2}, {\[Theta]1, 0, 2 \[Pi]},
>     PlotStyle -> {Black},
>     PlotPoints -> 41]];
>
>insideline =
>   First[ParametricPlot3D[{4.9 Cos[\[Theta]1],
>      4.9 Sin[\[Theta]1], -0.2}, {\[Theta]1, 0, 2 \[Pi]},
>     PlotStyle -> {Red},
>     PlotPoints -> 41]];
>
>Show[Graphics3D[
>   {cylinder,
>    outsideline,
>    insideline}],
>  Lighting -> "Neutral",
>  ViewPoint -> {1.718, -2.747, 0.975},
>  Boxed -> False

As part of the default hidden surface removal algorithm, Mathematica
pushes lines towards the viewer to achieve the correct
sorting.  Given a polygon and a line which are coplanar and
overlapping this makes the line draw consistently in front of the
polygon as is expected.  In some cases such the one you've
discovered, this can also incorrectly make lines that are behind
polygons appear to be in front.

The problem is not related to the sides of the surface.  The black
line happens to poke though the cylinder when it passes behind the
cylinder at the part of the cylinder that is most distant from the
view point (the red line passes behind the cylinder closer to the
view point).  Inaccuracies of this nature are more likely to be
observed at a greater distance from the view point all other things
being equal.

One way to avoid the problem you have encountered is to introduce
transparency which causes Mathematica to automatically use a
different hidden surface removal algorithm that is slower and
consumes more memory but that better handles cases like this.  Here I
use Opacity[0.999] which is enough transparency to trigger a change
in the hidden surface algorithm, but not so much as to make objects
in the scene appear transparent.

Show[Graphics3D[{Opacity[0.999], cylinder, outsideline, insideline}],
Lighting -> "Neutral", ViewPoint -> {1.718, -2.747, 0.975}, Boxed -> False]

Chris Hill
Wolfram Research

```

• Prev by Date: Re: Why aren't both sides of a surface equally opaque?
• Next by Date: Re: plot error messages are completelly missing
• Previous by thread: Why aren't both sides of a surface equally opaque?
• Next by thread: Re: Why aren't both sides of a surface equally