MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: 3D-plot over a triangle

  • To: mathgroup at smc.vnet.net
  • Subject: [mg65133] Re: 3D-plot over a triangle
  • From: carlos at colorado.edu
  • Date: Wed, 15 Mar 2006 06:29:32 -0500 (EST)
  • References: <duudid$i2k$1@smc.vnet.net><dv694g$o51$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Here is the code of the plot-function-over-trig module in case
somebody wants to try it.  It is *very* slow but to
produce a few plots for a paper or report that is not
a major concern - clean looks are more important.

PlotTriangleShapeFunction[xytrig_,f_,Nsub_,aspect_]:=Module[
 {Ni,line3D={},poly3D={},zc1,zc2,zc3,xyf1,xyf2,xyf3,
  xc,yc, x1,x2,x3,y1,y2,y3,z1,z2,z3,iz1,iz2,iz3,d},
 {{x1,y1,z1},{x2,y2,z2},{x3,y3,z3}}=Take[xytrig,3];
  xc={x1,x2,x3}; yc={y1,y2,y3}; Ni=Nsub*3;
  For[iz1=1,iz1<=Ni,iz1++, For [iz2=1,iz2<=Ni-iz1,iz2++,
      iz3=Ni-iz1-iz2; If [iz3<=0, Continue[]]; d=0;
      If [Mod[iz1+2,3]==0&&Mod[iz2-1,3]==0, d=  1];
      If [Mod[iz1-2,3]==0&&Mod[iz2+1,3]==0, d=-1];
      If [d==0, Continue[]];
      zc1=N[{iz1+d+d,iz2-d,iz3-d}/Ni];
      zc2=N[{iz1-d,iz2+d+d,iz3-d}/Ni];
      zc3=N[{iz1-d,iz2-d,iz3+d+d}/Ni];
      xyf1={xc.zc1,yc.zc1,f[zc1[[1]],zc1[[2]],zc1[[3]]]};
      xyf2={xc.zc2,yc.zc2,f[zc2[[1]],zc2[[2]],zc2[[3]]]};
      xyf3={xc.zc3,yc.zc3,f[zc3[[1]],zc3[[2]],zc3[[3]]]};
      AppendTo[poly3D,Polygon[{xyf1,xyf2,xyf3}]];
      AppendTo[line3D,Line[{xyf1,xyf2,xyf3,xyf1}]]
   	]];
  Show[Graphics3D[RGBColor[1,0,0]],Graphics3D[poly3D],
	   Graphics3D[Thickness[.002]],Graphics3D[line3D],
	   Graphics3D[RGBColor[0,0,0]],Graphics3D[Thickness[.005]],
	   Graphics3D[Line[xytrig]],PlotRange->All,
	   BoxRatios->{1,1,aspect},Boxed->False]
	];

(* test statements *)
xyc1={0,0,0}; xyc2={3,0,0}; xyc3={Sqrt[3],3/2,0};
xytrig=N[{xyc1,xyc2,xyc3,xyc1}]; Nsub=16;

N1[zeta1_,zeta2_,zeta3_]:=(9/2)*zeta1*(zeta1-1/3)*(zeta1-2/3);
N2[zeta1_,zeta2_,zeta3_]:=(9/2)*zeta2*(zeta2-1/3)*(zeta2-2/3);
N3[zeta1_,zeta2_,zeta3_]:=(9/2)*zeta3*(zeta3-1/3)*(zeta3-2/3);
N4[zeta1_,zeta2_,zeta3_]:=(27/2)*zeta1*zeta2*(zeta1-1/3);
N5[zeta1_,zeta2_,zeta3_]:=(27/2)*zeta2*zeta1*(zeta2-1/3);
N6[zeta1_,zeta2_,zeta3_]:=(27/2)*zeta2*zeta3*(zeta2-1/3);
N7[zeta1_,zeta2_,zeta3_]:=(27/2)*zeta3*zeta2*(zeta3-1/3);
N8[zeta1_,zeta2_,zeta3_]:=(27/2)*zeta3*zeta1*(zeta3-1/3);
N9[zeta1_,zeta2_,zeta3_]:=(27/2)*zeta1*zeta3*(zeta1-1/3);
N10[zeta1_,zeta2_,zeta3_]:=27*zeta1*zeta2*zeta3;
PlotTriangleShapeFunction[xytrig,N1,Nsub,1/2];
PlotTriangleShapeFunction[xytrig,N2,Nsub,1/2];
PlotTriangleShapeFunction[xytrig,N3,Nsub,1/2];
PlotTriangleShapeFunction[xytrig,N4,Nsub,1/3];
PlotTriangleShapeFunction[xytrig,N5,Nsub,1/3];
PlotTriangleShapeFunction[xytrig,N6,Nsub,1/3];
PlotTriangleShapeFunction[xytrig,N7,Nsub,1/3];
PlotTriangleShapeFunction[xytrig,N8,Nsub,1/3];
PlotTriangleShapeFunction[xytrig,N9,Nsub,1/3];
PlotTriangleShapeFunction[xytrig,N10,Nsub,1/4];


  • Prev by Date: Re: Total Derivative and Output Display Question
  • Next by Date: Re: Total Derivative and Output Display Question
  • Previous by thread: Re: 3D-plot over a triangle
  • Next by thread: Re: 3D-plot over a triangle