6
$\begingroup$

Problem statement

I want to extrude a parametric surface and colour its front faces, back faces and boundaries differently.

Define plot options

opts =
  {Axes -> False,
   Boxed -> False,
   ImageSize -> 400,
   Lighting -> "ThreePoint",
   PlotPoints -> 64,
   ViewPoint -> {2, 0, 0.5}};

Steinbach surface

Steinbach = {v Cos[u], v Sin[u], 1/2 u Cos[v]};

Plots without extrusion

Red front faces

front =
 ParametricPlot3D[
  Steinbach, {u, 0, 2 Pi}, {v, -4, 4},
  Evaluate @ opts,
  PlotLabel -> "Front",
  PlotStyle -> Directive[FaceForm[Red, Yellow]]];

Red back faces

back =
 ParametricPlot3D[
  Steinbach, {u, 0, 2 Pi}, {v, -4, 4},
  Evaluate @ opts,
  PlotLabel -> "Back",
  PlotStyle -> Directive[FaceForm[Yellow, Red]]];

Yellow boundary

boundary =
 ParametricPlot3D[
  Steinbach, {u, 0, 2 Pi}, {v, -4, 4},
  Evaluate @ opts,
  BoundaryStyle -> Directive[Yellow, Thickness[0.01]],
  PlotLabel -> "Edges",
  PlotStyle -> Red];

Display together

GraphicsRow[{front, back, boundary},
 Dividers -> All,
 FrameStyle -> LightGray]

enter image description here

Plots with extrusion

Unfortunately, when I extrude the surface (using the undocumented options Method -> {"Extrusion" -> 0.1} or PlotTheme -> "ThickSurface", the different face colours vanish:

ParametricPlot3D[
 Steinbach, {u, 0, 2 Pi}, {v, -4, 4},
 Evaluate @ opts,
 Method -> {"Extrusion" -> 0.1},
 PlotStyle -> Directive[FaceForm[Red, Yellow]]]

enter image description here

I don't have this problem with my Blender / Python application which extrudes ("solidifies") respecting face colour directives:

enter image description here

enter image description here

Question

How can I extrude with different face and boundary colours like in the above Blender image collage?

$\endgroup$

2 Answers 2

6
$\begingroup$
  • At first we can set the PlotRange->{-3,3} to cut the surface to see that although the outisde of the thick surface is red, the inside of such thick surface is yellow.
ParametricPlot3D[Steinbach, {u, 0, 2  Pi}, {v, -4, 4}, Evaluate@opts, 
 Method -> {"Extrusion" -> 1}, 
 PlotStyle -> Directive[FaceForm[Red, Yellow], Opacity[.9]], 
 PlotRange -> {-3, 3}]

enter image description here

  • We take some code from VertexNormals.( Application, normalsShow)
  • We Cases the VertexNormals and Polygon and Line from the plot.We move the vertex along the VertexNormals to get another surface and Thread the Line to get the body side.
Clear["Global`*"];
opts = {Axes -> False, Boxed -> False, ImageSize -> 400, 
   Lighting -> "ThreePoint", PlotPoints -> 64, 
   ViewPoint -> {2, 0, 0.5}};
g = ParametricPlot3D[{v Cos[u], v Sin[u], 1/2 u Cos[v]}, {u, 0, 
    2 Pi}, {v, -4, 4}, PlotStyle -> Directive[FaceForm[Red, Yellow]], 
   BoundaryStyle -> Transparent, Mesh -> None, Evaluate@opts];
{pl, vl, prims} = 
  First@Cases[g, 
    GraphicsComplex[pl_, prims_, VertexNormals -> vl_, 
      opts___?OptionQ] :> {pl, vl, prims}, Infinity];
thickness = .1;
h = thickness/2;
lineindexs = Cases[prims, _Line, -1][[1, 1]];
Graphics3D[{GraphicsComplex[pl + h*vl, prims, VertexNormals -> vl], 
  GraphicsComplex[pl - h*vl, prims, VertexNormals -> vl], 
  GraphicsComplex[
   Join[pl + h*vl, pl - h*vl], {Red, EdgeForm[], 
    MapThread[
     Polygon[Join[#1, Reverse@#2]] &, {Partition[lineindexs, 2, 1, 1],
       Partition[lineindexs + Length@vl, 2, 1, 1]}]}]}, 
 Boxed -> False, ViewPoint -> {2, 0, 0.5}]
% // DiscretizeGraphics // Area

299.88.

enter image description here

$\endgroup$
2
$\begingroup$

This is rather an workaround that creates a separate "extruded" surface (there might be a much more direct way to do it)

opts = {Axes -> False, Boxed -> False, ImageSize -> 400, Lighting -> "ThreePoint"
   , PlotPoints -> 64, ViewPoint -> {-2, 0, 0.5}, MeshStyle -> None};

steinbach = {v Cos[u], v Sin[u], 1/2 u Cos[v]};
steinbachExtruded = steinbach + 0.06 Normalize[Cross[D[steinbach, u], D[steinbach, v]]];

plotYellow = 
  ParametricPlot3D[steinbachExtruded, {u, 0, 2 Pi}, {v, -4, 4},
      Evaluate@opts, PlotStyle -> Directive[FaceForm[Yellow]]];

plotRed = 
  ParametricPlot3D[steinbach, {u, 0, 2  Pi}, {v, -4, 4}
   , Evaluate@opts, Method -> {"Extrusion" -> 0.1}, PlotStyle -> Directive[FaceForm[Red]]];
   
Show[plotRed, plotYellow]

enter image description here

$\endgroup$

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.