Holes in Surfaces

Method 1

This method allows you to punch holes in a parametrized surface, with the positions of the holes specified by their parameter values.

Code

listavg[l_] := (Drop[l,1]+Drop[l,-1])/2

Checkrange[min_,max_,l_] := Map[ N[(#>=min)&&(#<=max)]&, l ]

hole[ a_, b_, l_, c_, d_, m_ ] := 
Position[
	   Outer[  And,
		   Checkrange[a,b,listavg[l]],
		   Checkrange[c,d,listavg[m]]
		],
	   True
        ]

punchhole[ s_, h_ ] := MapAt[ (Null)&, s, h]

Sample

f[r_,t_] := Block[ {c = Cos[t], s = Sin[t]}, {r c, r s, c s} ]

rs = NewRange[ 0,1, 10]

ts = NewRange[ 0, 2Pi, 20]

pts3d = Outer[ f, rs, ts ];

surf = MakeQuads[pts3d];

h = hole[ .7, .95, rs, 3Pi/2, 1.9 Pi, ts ];

s = punchhole[ surf, h ];

h = hole[ .2, .4, rs, 0, Pi/4, ts ];

s = punchhole[ s, h ];

t = Select[ Flatten[s], (!SameQ[#,Null])& ];

Show[Graphics3D[t]];

Method 2

This method simply clips out all the polygons contained within a given volume of space.

Code

Within[ {{a_,b_},{c_,d_},{e_,f_}}, {{g_,h_},{i_,j_},{k_,l_}} ] :=
            N[
                (a >= g) && (b <= h) &&
         	(c >= i) && (d <= j) &&
         	(e >= k) && (f <= l)
             ]

BoundingBox[ p_Polygon ] :=
	Map[ {Min[#],Max[#]}&, Transpose[ p[[1]] ] ]

Sample

<<ParametricPlot3D.m

s = ParametricPlot3D[{x,y,Sin[x]Cos[y]},{x,0,2Pi},{y,0,2Pi}];

vol = {{5Pi/8,7Pi/4},{Pi/4,Pi},{-10,10}};

Show[ Graphics3D[
			Select[ s[[1]], Not[Within[BoundingBox[#],vol]]& ]
	] ];

Useful Functions

ExtrinsicCut[s_,vol_ ] := Show[ Graphics3D[
			Select[ s[[1]], Not[Within[BoundingBox[#],vol]]& ]
	] ]

ExtrinsicCut2[s_,vol_ ] := Show[ Graphics3D[
			Select[ s[[1]], Not[Within[BoundingBox[#],vol]]& ]
	], Boxed->False]

NewRange

This is a modified Range function.  Instead of the step size, you specify the number of subintervals.

NewRange[ first_, last_, howmany_ ] :=
	Block[
			{ r = Range[0,howmany]/howmany },
			first Reverse[r] + last r
		 ]

MakeQuads

Turns an (m+1)-by-(n+1) array of pts {x,y,z} in space into an m-by-n array of quadrilaterals.

This function actually does (almost) the same job as the MakePolygons function from the ParametricPlot3D.m package, and is slower besides.  But this version is a little easier to understand.  Also, this function preserves the array structure: you get an array of polygons rather than a list of polygons.  This can be useful in certain circumstances.  Still, you might want to use MakePolygons instead if you are concerned about speed.

MakeQuads[w_] :=
		Block[
				{
					a,b,c,d
				},
				a = Transpose[w];
				b = Transpose[ Drop[a,-1] ];
				d = Transpose[ Drop[a,1] ];
				a = Drop[b,-1];
				b = Drop[b,1];
				c = Drop[d,1];
				d = Drop[d, -1];
				d = {a, b, c, d};
				d = Transpose[d,{3,1,2,4}];
				d = Map[ Polygon, d, {2} ]
			 ];

Example 3

s = ParametricPlot3D[{Sin[v]Cos[u],Sin[v]Sin[u],Cos[v]},{u,0,2Pi},{v,Pi/8,Pi}]

vol = {{1/2,3/4},{1/2,3/4},{-10,10}};

ExtrinsicCut[s,vol]