POV-Ray : Newsgroups : povray.advanced-users : triangle centers : Re: triangle centers Server Time
29 Jul 2024 00:30:59 EDT (-0400)
  Re: triangle centers  
From:
Date: 20 Jul 2003 02:43:43
Message: <3f1a3a1f$1@news.povray.org>
// Hi David,
//
// "my" solution (from mathforum.org) also works in 3D; the
// following scene will convince you!
//
//   Sputnik


//=== 3D incircle demonstration =========================================

// +SP8 +EP8 +A0.1 +AM2 +R2 -FN


//=== calculate 3D-normal, 3D-midpoint and 3D-radius of 3D-triangle =====

#macro InCircle (P1, P2, P3, Normal, InMid, InRad)
  #local L12 = vlength(P2-P1);
  #local L13 = vlength(P3-P1);
  #local L23 = vlength(P3-P2);
  #local Peri = L12+L13+L23;
  #local Normal = vcross(P2-P1,P3-P1); // not yet normalized
  #local DoubleArea = vlength(Normal);
  #local Normal = Normal/DoubleArea; // =vnormalize(Normal)
  #declare InMid = (P1*L23+P2*L13+P3*L12)/Peri;
  #declare InRad = DoubleArea/Peri;
  #end//macro InCircle

//=======================================================================


// some initializations for demo scene
#declare T = 0.1; // thickness
#declare Shrink = 0; // also try 0.01 <=== !!!
#declare Rand = seed(154245648);
// dummy initialization (variables are used as macro parameter)
#declare N = <0,0,0>;
#declare M = <0,0,0>;
#declare R = 0;

// camera, light
#declare CamLoc = <0, 6, -4>;
#declare CamDir = vnormalize(CamLoc);
camera { location CamLoc look_at 0 }
light_source { <-2, 3, -4>*1000, rgb 1 }


// macro for random triangle without incircle
#macro RandomTriangle (Pos)
  // search for a "good" triangle
  #declare BadNormal = true;
  #while (BadNormal)
    // choose 3 random corner points
    #local C1 = <rand(Rand), rand(Rand), rand(Rand)>-0.5;
    #local C2 = <rand(Rand), rand(Rand), rand(Rand)>-0.5;
    #local C3 = <rand(Rand), rand(Rand), rand(Rand)>-0.5;
    // calculate normal, midpoint and radius of the incircle
    InCircle (C1, C2, C3, N, M, R)
    // reject if not rougly facing the camera
    #declare BadNormal = ( abs(vdot(N, CamDir)) < .7 );
    #end//while BadNormal
  // create thick triangle, cut out its "incylinder"
  difference {
    intersection {
      plane {  N, T/2 translate C1 }
      plane { -N, T/2 translate C1 }
      plane { vcross(N, C1-C2), -Shrink*R translate C1 }
      plane { vcross(N, C2-C3), -Shrink*R translate C2 }
      plane { vcross(N, C3-C1), -Shrink*R translate C3 }
      }
    cylinder { M+N*T, M-N*T, R }
    bounded_by { box {
      <min(C1.x,C2.x,C3.x), min(C1.y,C2.y,C3.y), min(C1.z,C2.z,C3.z)>-T,
      <max(C1.x,C2.x,C3.x), max(C1.y,C2.y,C3.y), max(C1.z,C2.z,C3.z)>+T
      } }
    texture {
      pigment { color rgb <rand(Rand), rand(Rand), rand(Rand)>*.7+.3 }
      finish { ambient .4 diffuse .6 }
      }
    no_shadow
    translate Pos
    }
  #end//macro RandomTriangle

// a cloud of triangles
#declare X = -2;
#while (X<=2)
  #declare Y = 0;
  #while (Y<=3)
    #declare Z = -2;
    #while (Z<=0)
      RandomTriangle (<X,Y,Z>)
      #declare Z = Z+1;
      #end//while Z
    #declare Y = Y+1;
    #end//while Y
  #declare X = X+1;
  #end//while X


//=== END ===============================================================


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.