// Persistence of Vision Ray Tracer Scene Description File
// File: ?.pov
// Vers: 3.5
// Desc: Trapizoids wire/faces/solids
// Date: 1/28/05
// Auth: LR
//
#ifndef(TRAPIZOID_LR)
#declare TRAPIZOID_LR=1;
// a - base x direction
// b - base z direction
// c - top x direction
// d - top z direction
// h - height
// r - >0 roundness radius of curve ,=0 sharp, <0 abs(bevel) 
// F - type 0- wire frame 1- inclose with triangles 
//          2-solid union 3- solid merge

#macro Trapizod(a,b,c,d,h,r,F)
 #if (F=0)#local r=abs(r); #end
 #local w1=r;
 #if (w1<0) #local w1=abs(r); #end
 #local Lp1=<w1-a,w1,w1-b>;
 #local Lp2=<w1-a,w1,b-w1>;
 #local Lp3=<a-w1,w1,b-w1>;
 #local Lp4=<a-w1,w1,w1-b>;
 #local Hp1=<w1-c,h-w1,w1-d>;
 #local Hp2=<w1-c,h-w1,d-w1>;
 #local Hp3=<c-w1,h-w1,d-w1>;
 #local Hp4=<c-w1,h-w1,w1-d>;

#if ((F=3)&(r>0)) merge{// #debug"Hit1\n"
#else #if (r>0) union{ #end //#debug"Hit2\n" 
#end

#if (r>0)//edges
 cylinder{Lp1,Lp2,r}
 cylinder{Lp2,Lp3,r}
 cylinder{Lp3,Lp4,r}
 cylinder{Lp4,Lp1,r}
 sphere{Lp1,r}
 sphere{Lp2,r}
 sphere{Lp3,r}
 sphere{Lp4,r}
 cylinder{Hp1,Hp2,r}
 cylinder{Hp2,Hp3,r}
 cylinder{Hp3,Hp4,r}
 cylinder{Hp4,Hp1,r}
 sphere{Hp1,r}
 sphere{Hp2,r}
 sphere{Hp3,r}
 sphere{Hp4,r}
 cylinder{Lp1,Hp1,r}
 cylinder{Lp2,Hp2,r}
 cylinder{Lp3,Hp3,r}
 cylinder{Lp4,Hp4,r}
#end
#if (F>0)//calc sides
  #local w1=abs(r);
  #local An=atan2(a-c,h-w1);
   #local An2=pi/2-An;
   #local Ax=sin(An2)*w1;
   #local Ay=cos(An2)*w1;
   #if (a-c=0) #local Ax=w1; #local Ay=0; #end
   #if (a-c<0) #local Ax=Ax; #local Ay=-Ay;#end
  #if (r=0) #local Ax=0; #local Ay=0; #end

  #local Bq1=Lp1-y*w1; #local Bq2=Lp2-y*w1;
  #local Bq3=Lp3-y*w1; #local Bq4=Lp4-y*w1;
   #local Tq1=Hp1+y*w1; #local Tq2=Hp2+y*w1;
   #local Tq3=Hp3+y*w1; #local Tq4=Hp4+y*w1;
  #local Aw=<-Ax,Ay,0>;
   #local Fx1=Lp1+Aw; #local Fx2=Lp2+Aw;
   #local Fx3=Hp2+Aw; #local Fx4=Hp1+Aw;
  #local Aw=<Ax,Ay,0>;
   #local FX1=Lp3+Aw; #local FX2=Lp4+Aw;
   #local FX3=Hp4+Aw; #local FX4=Hp3+Aw;
  #local An=atan2(b-d,h-w1);
  #local An2=pi/2-An;
  #local Ax=sin(An2)*w1;
  #local Ay=cos(An2)*w1;
  #if (b-d=0) #local Ax=w1; #local Ay=0; #end
  #if (b-d<0) #local Ax=Ax; #local Ay=-Ay;#end
  #local Aw=<0,Ay,-Ax>;
   #local FZ1=Lp1+Aw; #local FZ2=Lp4+Aw;
   #local FZ3=Hp4+Aw; #local FZ4=Hp1+Aw;
  #local Aw=<0,Ay,Ax>;
   #local Fz1=Lp2+Aw; #local Fz2=Lp3+Aw;
   #local Fz3=Hp3+Aw; #local Fz4=Hp2+Aw;

mesh{  //faces
  triangle{Bq1,Bq2,Bq3}
  triangle{Bq1,Bq4,Bq3}
   triangle{Tq1,Tq2,Tq3}
   triangle{Tq1,Tq4,Tq3}
  triangle{Fx1,Fx2,Fx3 }
  triangle{Fx1,Fx4,Fx3}
   triangle{FX1,FX2,FX3}
   triangle{FX1,FX4,FX3}
  triangle{Fz1,Fz2,Fz3}
  triangle{Fz1,Fz4,Fz3}
   triangle{FZ1,FZ2,FZ3}
   triangle{FZ1,FZ4,FZ3}
 
 #if ((F>0)&(r!=0))// corners
   triangle{Bq1,FZ1,Fx1} triangle{Tq1,FZ4,Fx4}
   triangle{Bq2,Fz1,Fx2} triangle{Tq2,Fz4,Fx3}
   triangle{Bq3,Fz2,FX1} triangle{Tq3,Fz3,FX4}
   triangle{Bq4,FZ2,FX2} triangle{Tq4,FZ3,FX3}
   
   triangle{Fx4,FZ1,Fx1} triangle{FZ1,FZ4,Fx4}
   triangle{Fx3,Fz1,Fx2} triangle{Fz1,Fz4,Fx3}
   triangle{FX4,Fz2,FX1} triangle{Fz2,Fz3,FX4}
   triangle{FX3,FZ2,FX2} triangle{FZ2,FZ3,FX3}
  
   triangle{Bq1,Fx1,Bq2} triangle{Bq2,Fx2,Fx1}
   triangle{Bq2,Fz1,Bq3} triangle{Bq3,Fz2,Fz1}
   triangle{Bq3,FX1,Bq4} triangle{Bq4,FX1,FX2}
   triangle{Bq4,FZ2,Bq1} triangle{Bq1,FZ1,FZ2}
  
   triangle{Tq1,Fx4,Tq2} triangle{Tq2,Fx4,Fx3}
   triangle{Tq2,Fz4,Tq3} triangle{Tq3,Fz4,Fz3}
   triangle{Tq3,FX4,Tq4} triangle{Tq4,FX3,FX4}
   triangle{Tq4,FZ3,Tq1} triangle{Tq1,FZ3,FZ4}
 #end
 #if (F>1) inside_vector <0, 0, 1> #end
 }
 #end
 #if (r>0) } #end//#debug"Hit3\n" 
#end

//----------------PreView-----------------

 #ifndef(Get)
 #version 3.6;
 #include "colors.inc"
 //global_settings { assumed_gamma 2.2 }
 camera {location<0,10,-20>
  right x*image_width/image_height
  look_at<0,5,0>
 }
 light_source {<-20, 20, -20> rgb 1}
 light_source {<0, 20, -20> rgb 1}
 plane { y, 0  pigment {Gold}}

//-------display trapizoids--------------------------------
 object{Trapizod(3,3,2,1,6,.75,3) rotate <0,45,0>
 pigment{agate color_map{[0 rgbt <1,.1,.01,0>][1 rgbt <.5,.1,.01,0>]}
  turbulence .1} 
 normal {agate turbulence .1}
 finish{specular .1 roughness .01 }
  translate z*9}
 
 object{Trapizod(3,3,2,2,4,.5,1) pigment{Yellow}rotate y*45 translate<-8,0,8>}
 object{Trapizod(3,3,2,2,4,0,1) pigment{Yellow}rotate -y*45 translate<8,0,8>}
 object{Trapizod(1,1,.25,1.5,2,-.1,1) pigment{Gold} translate <8,0,-3>}
 object{Trapizod(1,1,.5,.5,2,-.2,2) pigment{Gold} translate <-8,0,-3>}

  text {ttf "timrom.ttf" "F=0 :wrire Frame" .1, 0 scale 1.5
    pigment {Pink} translate <-14,9,8>no_shadow}
  text {ttf "timrom.ttf" "F=1 :triangle Mesh2" .1, 0 scale 1.5
    pigment {Pink} translate <-14,7,8>no_shadow}
  text {ttf "timrom.ttf" "F=2 : Solid union" .1, 0 scale 1.5
    pigment {Pink} translate <1,9,8>no_shadow}
  text {ttf "timrom.ttf" "F=3 : Solid merge" .1, 0 scale 1.5
    pigment {Pink} translate <1,7,8>no_shadow}

 object{Trapizod(3,3,2,2,4,-.1,0)
  pigment{agate color_map{[0 rgbt <.7,.7,.01,0>][1 rgbt <.4,.4,.01,0>]}
   turbulence .1} 
  normal {agate turbulence .1}
 }

  text {ttf "timrom.ttf" "Trapizod(a,b,c,d,h,r,F)" .1, 0
    pigment {White} translate <-4,12,-5>no_shadow}

 cylinder{0,-z*2.5,.1 pigment{White}}
 cone{-z*2.9,0,-z*2.3,.3 pigment{rgb 1}} text {ttf "timrom.ttf" "b" .1, 0 
    pigment {White} rotate x*90
    scale <2,1,2>translate <.2,.5,-2.5>no_shadow}
 cylinder{0,-x*2.5,.1 pigment{rgb 1}}
 cone{-x*2.9,0,-x*2.3,.3 pigment{rgb 1}}
   text {ttf "timrom.ttf" "a" .1, 0 
    pigment {rgb 1} //rotate x*90
    scale <2,1,2>translate <-1.5,.5,0>no_shadow}
 cylinder{0,y*3.9,.1 pigment{White}}
 cone{y*1.5,.3,y*2.3,0 pigment{rgb 1}}
   text {ttf "timrom.ttf" "h" .1, 0 
    pigment {White}
    scale <2,1,2>translate <.3,1,0>no_shadow}
 cylinder{y*3.9,<0,3.9,-1.5>,.1 pigment{White}}
 cone{-z*1.9+y*3.9,0,-z*1.3+y*3.9,.3 pigment{rgb 1}}
  text {ttf "timrom.ttf" "d" .1, 0 
    pigment {White} //rotate x*90
    scale <2,1,2>translate <.2,4,-1.5>no_shadow}
 cylinder{y*3.9,<-1.5,3.9,0>,.1 pigment{White}}
 cone{-x*1.9+y*3.9,0,-x*1.3+y*3.9,.3 pigment{rgb 1}}
  text {ttf "timrom.ttf" "c" .1, 0 
    pigment {White} //rotate x*90
    scale <2,1,2>translate <-1,4.5,0>no_shadow}
 cone{<-3.5,.5,-3>,.2,<-3,.5,-3>,0 pigment{White}} 
  text {ttf "timrom.ttf" "r" .1, 0 
    pigment {White} //rotate x*90
    scale <2,1,2>translate <-4,.5,-3>no_shadow}
  sphere{0,.3 pigment{rgb x}}
  sphere{y*3.9,.3 pigment{rgb x}}
#end// end of not get
#end//end of include