Re: is the visibility of a Polygon[] exposed?

*To*: mathgroup at smc.vnet.net*Subject*: [mg83749] Re: is the visibility of a Polygon[] exposed?*From*: m.r at inbox.ru*Date*: Thu, 29 Nov 2007 06:37:51 -0500 (EST)*References*: <figuou$foo$1@smc.vnet.net> <fijick$io6$1@smc.vnet.net>

On Nov 28, 5:11 am, m... at inbox.ru wrote: > On Nov 27, 5:24 am, congruentialumina... at yahoo.com wrote: > > > > > Hello Mathematica UG: > > > Is it possible for my code to tell if a Polygon (in my graphics > > object) is visible? > > > I assume that this is based upon (or is affected by) the ViewPoint-> > > setting. > > > Further, I assume that the kernel is deriving this somewhere to do > > rendering. Do I have any access to this? > > > If I evaluate: > > > q = PolyhedronData["SnubCube"] > > > I can see the component Polygon[] and GraphicsComplex[] objects that > > make up the Graphics3D[]. I want to make a code decision based on > > whether a face is showing. > > > TIA. > > > Regards..Roger W. > > This doesn't look perfect because it draws every edge twice, but it > gives a general idea: > > DynamicModule[{gr, p, cent}, > {p, cent} = {Max@ #, Mean@ #}&@ > N@ PolyhedronData["SnubCube", "VertexCoordinates"]; > p *= 2 {1.3, -2.4, 2.}; > gr = PolyhedronData["SnubCube", "Faces"] // N // Normal; > gr = gr /. Polygon[L_?MatrixQ, ___] :> > {Dynamic@ If[Det@ > {L[[2]] - L[[1]], L[[3]] - L[[1]], p - cent - L[[1]]} >= 0, > Thick, Dashed], > Line@ Append[L, L[[1]]]}; > Graphics3D[gr, Boxed -> False, > ViewCenter -> Dynamic[Automatic, None], > ViewVector -> Dynamic@ {p, cent}] > ] > > Maxim Rytin > m... at inbox.ru Except I made a mistake, p - cent - L[[1]] should be just p - L[[1]]. cent can be anywhere: DynamicModule[{gr, p, cent, cent1, cent2, r}, {p, cent1, cent2} = {Max@ Abs@ #, Mean@ #, First@ #}&@ N@ PolyhedronData["SnubCube", "VertexCoordinates"]; p *= 2 {1.3, -2.4, 2.}; cent = cent1; r = Norm[p - cent]; gr = PolyhedronData["SnubCube", "Faces"] // N // Normal; gr = gr /. Polygon[L_?MatrixQ, ___] :> {Dynamic@ If[Det@ {L[[2]] - L[[1]], L[[3]] - L[[1]], p - L[[1]]} >= 0, Thick, Dashed], Line@ Append[L, L[[1]]]}; Manipulate[ Graphics3D[{gr, {Red, AbsolutePointSize[5], Point[Dynamic@ cent]}}, Boxed -> False, ViewCenter -> Dynamic[Automatic, None], ViewVector -> Dynamic[{p, cent}, (p = r Normalize[#[[1]] - #[[2]]] + #[[2]])&]], {{s, False, "Fixed Vertex"}, Checkbox[Dynamic[s, (cent = If[s = #, cent2, cent1])&]]&}] ] Maxim Rytin m.r at inbox.ru