POV-Ray : Newsgroups : povray.general : Newbie Question: a simple polygon in 3D : Re: Newbie Question: a simple polygon in 3D Server Time
2 Aug 2024 22:12:00 EDT (-0400)
  Re: Newbie Question: a simple polygon in 3D  
From: Tor Olav Kristensen
Date: 17 Jul 2004 09:53:05
Message: <40f92f41$1@news.povray.org>
nomail@nomail wrote:
> Tor Olav Kristensen <tor### [at] TOBEREMOVEDhotmailcom> wrote:
> 
>>nomail@nomail wrote:
>>
>>If the number of sampled points from each slice contour
>>is equal, then you can write a little macro that produces
>>triangles that connects each pair of successive slices.
>>
>>(All the triangles can be merged into a mesh.)
...
> Thanks Tor for your response.
> I saw your web-site. The photos were great, but I am still newbie, and your
> images are very complicated for me...
> Do you have a simple example??.

See below for an example.

Note that I have commented out some points in the second contour
in order to get the same amount of samples around each slice.

Better results can be achieved by using a mesh2{} mesh instead of
triangles.

The code can also be made more efficient (and optimal in other ways),
but I've tried to keep it simple.


Tor Olav


// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

#macro Slice(ContourA, ContourB, FromZ, ToZ)

   #local Size = dimension_size(ContourA, 1);

   #local Cnt = 0;
   #while (Cnt < Size - 1)
     #local p1 = ContourA[Cnt] + z*FromZ;
     #local p2 = ContourB[Cnt] + z*ToZ;
     #local p3 = ContourA[Cnt + 1] + z*FromZ;
     #local p4 = ContourB[Cnt + 1] + z*ToZ;
     triangle { p1, p2, p3 }
     triangle { p2, p3, p4 }
     #local Cnt = Cnt + 1;
   #end // while

#end // macro Slice

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

#declare Contour1 =
   array[84] {
     <346, 224, 0>,
     <345, 224, 0>,
     <345, 227, 0>,
     <344, 227, 0>,
     <344, 229, 0>,
     <343, 229, 0>,
     <343, 231, 0>,
     <342, 231, 0>,
     <342, 232, 0>,
     <341, 232, 0>,
     <341, 233, 0>,
     <340, 233, 0>,
     <340, 234, 0>,
     <339, 234, 0>,
     <339, 235, 0>,

     <337, 235, 0>,
     <337, 236, 0>,
     <335, 236, 0>,
     <335, 237, 0>,

     <333, 237, 0>,
     <333, 238, 0>,
     <324, 238, 0>,
     <324, 237, 0>,
     <322, 237, 0>,
     <322, 236, 0>,
     <320, 236, 0>,
     <320, 235, 0>,

     <318, 235, 0>,
     <318, 234, 0>,
     <317, 234, 0>,
     <317, 233, 0>,
     <316, 233, 0>,
     <316, 232, 0>,
     <315, 232, 0>,
     <315, 231, 0>,
     <314, 231, 0>,
     <314, 229, 0>,
     <313, 229, 0>,
     <313, 227, 0>,
     <312, 227, 0>,
     <312, 224, 0>,

     <311, 224, 0>,
     <311, 215, 0>,
     <312, 215, 0>,
     <312, 212, 0>,
     <313, 212, 0>,
     <313, 210, 0>,
     <314, 210, 0>,
     <314, 208, 0>,
     <315, 208, 0>,
     <315, 207, 0>,
     <316, 207, 0>,
     <316, 206, 0>,
     <317, 206, 0>,
     <317, 205, 0>,
     <318, 205, 0>,
     <318, 204, 0>,

     <320, 204, 0>,
     <320, 203, 0>,
     <322, 203, 0>,
     <322, 202, 0>,
     <324, 202, 0>,
     <324, 201, 0>,
     <333, 201, 0>,
     <333, 202, 0>,
     <335, 202, 0>,
     <335, 203, 0>,
     <337, 203, 0>,
     <337, 204, 0>,

     <339, 204, 0>,
     <339, 205, 0>,
     <340, 205, 0>,
     <340, 206, 0>,
     <341, 206, 0>,
     <341, 207, 0>,
     <342, 207, 0>,
     <342, 208, 0>,
     <343, 208, 0>,
     <343, 210, 0>,
     <344, 210, 0>,
     <344, 212, 0>,
     <345, 212, 0>,
     <345, 215, 0>,
     <346, 215, 0>
   }


#declare Contour2 =
   array[84] {
     <346, 224, 0>,
     <345, 224, 0>,
     <345, 227, 0>,
     <344, 227, 0>,
     <344, 229, 0>,
     <343, 229, 0>,
     <343, 231, 0>,
     <342, 231, 0>,
     <342, 232, 0>,
     <341, 232, 0>,
     <341, 233, 0>,
     <340, 233, 0>,
     <340, 234, 0>,
     <339, 234, 0>,
     <339, 235, 0>,

//    <338, 235, 0>,
//    <338, 236, 0>,
     <337, 236, 0>,
     <337, 237, 0>,
     <335, 237, 0>,
     <335, 238, 0>,

     <332, 238, 0>,
     <332, 239, 0>,
     <324, 239, 0>,
     <324, 238, 0>,
     <321, 238, 0>,
     <321, 237, 0>,
     <319, 237, 0>,
     <319, 236, 0>,

     <318, 236, 0>,
     <318, 235, 0>,
     <317, 235, 0>,
     <317, 234, 0>,
     <316, 234, 0>,
     <316, 233, 0>,
     <315, 233, 0>,
     <315, 232, 0>,
     <314, 232, 0>,
     <314, 231, 0>,
     <313, 231, 0>,
     <313, 229, 0>,
//    <312, 229, 0>,
     <312, 227, 0>,

//    <311, 227, 0>,
     <311, 224, 0>,
//    <310, 224, 0>,
     <310, 214, 0>,

     <311, 214, 0>,
     <311, 211, 0>,
//    <312, 211, 0>,
     <312, 209, 0>,
     <313, 209, 0>,
     <313, 207, 0>,
     <314, 207, 0>,
     <314, 206, 0>,
     <315, 206, 0>,
     <315, 205, 0>,
     <316, 205, 0>,
     <316, 204, 0>,
     <317, 204, 0>,
     <317, 203, 0>,
     <318, 203, 0>,
     <318, 202, 0>,

     <319, 202, 0>,
     <319, 201, 0>,
     <321, 201, 0>,
     <321, 200, 0>,
     <324, 200, 0>,
     <324, 199, 0>,
     <332, 199, 0>,
     <332, 200, 0>,
     <335, 200, 0>,
     <335, 201, 0>,
     <337, 201, 0>,
     <337, 202, 0>,
//    <338, 202, 0>,
//    <338, 203, 0>,

     <339, 203, 0>,
     <339, 204, 0>,
     <340, 204, 0>,
     <340, 205, 0>,
     <341, 205, 0>,
     <341, 206, 0>,
     <342, 206, 0>,
     <342, 207, 0>,
     <343, 207, 0>,
     <343, 209, 0>,
     <344, 209, 0>,
     <344, 211, 0>,
     <345, 211, 0>,
     <345, 214, 0>,
     <346, 214, 0>
   }

union {
   Slice(Contour1, Contour2, -10, 0)
   pigment { color rgb <1, 0, 0> }
}

/*
union {
   Slice(Contour1, Contour2, 0, 10)
   pigment { color rgb <1, 0, 0> }
}

union {
   Slice(Contour1, Contour2, 10, 20)
   pigment { color rgb <1, 0, 0> }
}
*/

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

#declare pCenter = <311 + (346 - 311)/2, 199 + (239 - 199)/2, 0>;

camera {
   location <5, 4, -10>*10
   look_at <0, 0, 0>
   translate pCenter
}

background { color rgb <1, 1, 1>*0.4 }

light_source {
   <8, 10, 10>*100
   color rgb <1, 1, 1>
}

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7


Post a reply to this message

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