RE: Plot3D, how to plot only certain regions of a surface...
- To: mathgroup at smc.vnet.net
- Subject: [mg41674] RE: [mg41616] Plot3D, how to plot only certain regions of a surface...
- From: "David Park" <djmp at earthlink.net>
- Date: Fri, 30 May 2003 03:56:20 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
Barbara, I will make up a couple of functions and hope they are typical of your requirement. f1[x_, y_] := Cos[x]Sin[y] f2[x_, y_] := Sin[x]Cos[y] Needs["Graphics`Colors`"] First I will show how to do it using the regular Mathematica paradigm and then I will do it with DrawGraphics from my web site. I am going to use ParametricPlot3D because it produces Polygons primitives directly. Otherwise, you would have to convert Plot3D output from SurfaceGraphics to Graphics3D. plot1 = ParametricPlot3D[{x, y, f1[x , y]}, {x, -3, 3}, {y, -3, 3}]; We select all the Polygon primitives for the surface. They are just the first part of plot 1. polygons = First[plot1]; Next we make a rule that will eliminate each point in each polygon for which f1 < f2. highselectionrule = {x_?NumberQ, y_?NumberQ, z_?NumberQ} /; f1[x, y] < f2[x, y] -> Sequence[]; Sequence[] just eliminates an item an a list, in this case the list of points in a Polygon. (I learned this trick from one of the regulars on MathGroup, but I can't remember exactly who.) polygons2 = polygons /. highselectionrule; Now we can show only the part of the surface for which f1 > f2. Show[Graphics3D[{polygons2}], Axes -> True]; In this case, the result looks fairly good. But sometimes you will obtain jagged edges for the region. Now, for the DrawGraphics solution. Needs["DrawGraphics`DrawingMaster`"] What I am going to do is make a grid of polygons, and then trim the polygons so they satisfy the inequalities we want. I will obtain two resulting grids, one where f1 > f2 and one where f1 < f2. I will then raise both of them to 3D surfaces, but give them different surface colors. The result will be the f1 surface but colored Salmon where f1 > f2 and colored LightBlue where f1 < f2. This generates a 20 x 20 grid of polygons. polygrid = MakePolyGrid[{20, 20}, {{-3, -3}, {3, 3}}] // N; The following statements select and trim the polygons as to whether 0 < f1 - f2 < 1 or -1 < f1 - f2 < 0. polygrid2 = polygrid // TrimPolygons[f1[#1, #2] - f2[#1, #2] &, {0, 1}]; polygrid3 = polygrid // TrimPolygons[f1[#1, #2] - f2[#1, #2] &, {-1, 0}]; The following statements raise the two grids to the f1 3D surface. polygrid3D2 = polygrid2 // RaiseTo3D[f1[#1, #2] &]; polygrid3D3 = polygrid3 // RaiseTo3D[f1[#1, #2] &]; Now we can draw the two surfaces, using different SurfaceColors. NeutralLighting produces a set of lights for which we can control the saturation, brightness and ambient brackground. (You can also rotate them). Using a lower color saturation allows the colored surfaces to display better. The EdgeForm statements using the DrawGraphics ColorMix command produce edges that are the same color as the surface but a slightly darker shade. That is a way to have the edges show, but tone them down. With this technique the boundary regions are always smooth. Draw3DItems[ {SurfaceColor[Salmon], EdgeForm[ColorMix[Salmon, Black][0.4]], polygrid3D2, SurfaceColor[LightBlue], EdgeForm[ColorMix[LightBlue, Black][0.4]], polygrid3D3}, NeutralLighting[0.3, 0.5, 0.1], Axes -> True, ImageSize -> 500]; David Park djmp at earthlink.net http://home.earthlink.net/~djmp/ From: bhirtz at student.ethz.ch [mailto:bhirtz at student.ethz.ch] To: mathgroup at smc.vnet.net Hi everybody, I have a problem that I don't seem to be able to solve myself in a clean way: I have a function f1=f(x,y) and I plot it with Plot3D within the plotrange (0.01, Automatic). There is another function f2=f(x,y). Now, I would like to plot f1 only in those regions where f2 is positive. I did it like that: f3=If[f2>0, 1,0]; Plot3D[f1*f3,{x,xmin,xmax},{y, ymin, ymax},PlotRange->{0.01,Automatic}] This basically works. However, Mathematica draws vertical surfaces where f1 is clipped (i.e. from the local values of f1 to zero), although all zero values are not plotted due to the plot range {0.01,Automatic}. Those vertical surfaces simply look somewhat ugly. Any help is appreciated! Thanks, Barbara