POV-Ray : Newsgroups : povray.general : Array of points for use with bicubic patch Server Time
29 Jul 2024 16:18:49 EDT (-0400)
  Array of points for use with bicubic patch (Message 1 to 10 of 15)  
Goto Latest 10 Messages Next 5 Messages >>>
From: D103
Subject: Array of points for use with bicubic patch
Date: 25 Apr 2011 09:05:01
Message: <web.4db5716483b8d732964acb270@news.povray.org>
I am attempting to make a curtain out of bicubic patches. I want to create an
array which contains all the points, which is easy enough, but I'm not sure how
to then use the points in the patches.

This is the array I intend to use:

#declare BPatchPoints = array[4][16] {
  { //points for first patch }
  { //points for second patch }
  { //points for third patch }
  { //points for fourth patch }

Also, I'm wondering if I could use while loops to generate the points, which
would make it easier to add randomness. Again, I'm not sure how to go about
doing this, except perhaps using the loop to generate the array as well?


D103


Post a reply to this message

From: Le Forgeron
Subject: Re: Array of points for use with bicubic patch
Date: 25 Apr 2011 10:14:20
Message: <4db581bc$1@news.povray.org>
Le 25/04/2011 15:04, D103 nous fit lire :
> I am attempting to make a curtain out of bicubic patches. I want to create an
> array which contains all the points, which is easy enough, but I'm not sure how
> to then use the points in the patches.
> 
> This is the array I intend to use:
> 
> #declare BPatchPoints = array[4][16] {
>   { //points for first patch }
>   { //points for second patch }
>   { //points for third patch }
>   { //points for fourth patch }
> 
> Also, I'm wondering if I could use while loops to generate the points, which
> would make it easier to add randomness. Again, I'm not sure how to go about
> doing this, except perhaps using the loop to generate the array as well?

Have you read

> http://wiki.povray.org/content/Documentation:Tutorial_Section_3#Bicubic_Patch_Object

?

The corner of each grid should match. (aka, duplicate them)
The control points along the jointing line should also.

Do you really want to manage the 16 points of patch with 0-15, or use a
double index 0-3,0-3 instead ?

(array[n][4][4])

Or even simpler to understand: array[n][m][4][4]
n height
m width (as number of patch)


Post a reply to this message

From: D103
Subject: Re: Array of points for use with bicubic patch
Date: 25 Apr 2011 19:30:00
Message: <web.4db603442d1676e497b020200@news.povray.org>
Le_Forgeron <jgr### [at] freefr> wrote:
>
> Have you read
>
> >
http://wiki.povray.org/content/Documentation:Tutorial_Section_3#Bicubic_Patch_Object
>
> ?
Yes, I have, and with previous patches I used a similar method, but I'm trying
to find an easier way to control and change the points, for example, all the
points along a certain axis etc.
>
> The corner of each grid should match. (aka, duplicate them)
> The control points along the jointing line should also.
>
> Do you really want to manage the 16 points of patch with 0-15, or use a
> double index 0-3,0-3 instead ?
>
> (array[n][4][4])
>
> Or even simpler to understand: array[n][m][4][4]
> n height
> m width (as number of patch)

Hadn't thought of that, thanks.

Supposing I set up such an array, could I use it like this:


#declare P1 = 1;
#declare P2 = 1;
#while(P1<=4&P2<=4)
  bicubic_patch {
    type 1 u_steps 5 v_steps 5
    BPatchPoints[1][1][P1][P2]
  }
  bicubic_patch {
    type 1 u_steps 5 v_steps 5
    BPatchPoints[2][2][P1][P2]
  }
  bicubic_patch {
    type 1 u_steps 5 v_steps 5
    BPatchPoints[2][2][P1][P2]
  }
  bicubic_patch {
    type 1 u_steps 5 v_steps 5
    BPatchPoints[2][2][P1][P2]
  }
  #declare P1=P1+1;
  #if (P1=4)
    #declare P2=P2+1;
    #declare P1=1;
  #end
#end

Something tells me this isn't going to work, but I think that's the general idea
there.


Post a reply to this message

From: Warp
Subject: Re: Array of points for use with bicubic patch
Date: 26 Apr 2011 12:22:48
Message: <4db6f158@news.povray.org>
D103 <nomail@nomail> wrote:
> #declare P1 = 1;
> #declare P2 = 1;
> #while(P1<=4&P2<=4)
    ...
>   #declare P1=P1+1;
>   #if (P1=4)
>     #declare P2=P2+1;
>     #declare P1=1;
>   #end
> #end

  That's a really complicated way of making a nested loop. What's wrong
with the regular way of doing it?

#declare P1 = 0;
#while(P1 < 4)
  #declare P2 = 0;
  #while(P2 < 4)
    ...
    #declare P2 = P2 + 1;
  #end
  #declare P1 = P1 + 1;
#end

  (Note that array indices start from 0, not from 1.)

-- 
                                                          - Warp


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: Array of points for use with bicubic patch
Date: 26 Apr 2011 20:20:00
Message: <web.4db761002d1676e4c734aecd0@news.povray.org>
Le_Forgeron <jgr### [at] freefr> wrote:
> Le 25/04/2011 15:04, D103 nous fit lire :
> > I am attempting to make a curtain out of bicubic patches. I want to create an
> > array which contains all the points, which is easy enough, but I'm not sure how
> > to then use the points in the patches.
....
> Have you read
>
> >
http://wiki.povray.org/content/Documentation:Tutorial_Section_3#Bicubic_Patch_Object
>
> ?

This may also be relevant:

http://wiki.povray.org/content/Documentation:Reference_Section_4.1#Bicubic_Patch
http://wiki.povray.org/content/Documentation:Reference_Section_2.3#Array_Identifiers
http://wiki.povray.org/content/Documentation:Tutorial_Section_3.8#What_about_nested_loops.3F

http://wiki.povray.org/content/Documentation:Contents

--
Tor Olav
http://subcube.com


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: Array of points for use with bicubic patch
Date: 26 Apr 2011 21:30:01
Message: <web.4db76e442d1676e4c734aecd0@news.povray.org>
"D103" <nomail@nomail> wrote:
> Le_Forgeron <jgr### [at] freefr> wrote:
> >
> > Have you read
> >
> > >
http://wiki.povray.org/content/Documentation:Tutorial_Section_3#Bicubic_Patch_Object
> >
> > ?
> Yes, I have, and with previous patches I used a similar method, but I'm trying
> to find an easier way to control and change the points, for example, all the
> points along a certain axis etc.
> >
> > The corner of each grid should match. (aka, duplicate them)
> > The control points along the jointing line should also.
> >
> > Do you really want to manage the 16 points of patch with 0-15, or use a
> > double index 0-3,0-3 instead ?
> >
> > (array[n][4][4])
> >
> > Or even simpler to understand: array[n][m][4][4]
> > n height
> > m width (as number of patch)
>
> Hadn't thought of that, thanks.
>
> Supposing I set up such an array, could I use it like this:
>
>
> #declare P1 = 1;
> #declare P2 = 1;
> #while(P1<=4&P2<=4)
>   bicubic_patch {
>     type 1 u_steps 5 v_steps 5
>     BPatchPoints[1][1][P1][P2]
>   }
>   bicubic_patch {
>     type 1 u_steps 5 v_steps 5
>     BPatchPoints[2][2][P1][P2]
>   }
>   bicubic_patch {
>     type 1 u_steps 5 v_steps 5
>     BPatchPoints[2][2][P1][P2]
>   }
>   bicubic_patch {
>     type 1 u_steps 5 v_steps 5
>     BPatchPoints[2][2][P1][P2]
>   }
>   #declare P1=P1+1;
>   #if (P1=4)
>     #declare P2=P2+1;
>     #declare P1=1;
>   #end
> #end
>
> Something tells me this isn't going to work, but I think that's the general idea
> there.

Have a look at the code below.

Tor Olav

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

#version 3.6;

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

#declare PatchesInWidth = 2;
#declare PatchesInHeight = 2;

#declare PatchPoints =
  array[PatchesInHeight][PatchesInWidth][4][4] {
    {
      {
        { < 0,  0,  0>, < 1,  0,  0>, < 2,  0,  0>, < 3,  0,  0> },
        { < 0,  0,  1>, < 1,  1,  1>, < 2,  1,  1>, < 3,  0,  1> },
        { < 0,  0,  2>, < 1,  1,  2>, < 2,  1,  2>, < 3,  0,  2> },
        { < 0,  0,  3>, < 1,  0,  3>, < 2,  0,  3>, < 3,  0,  3> }
      },
      {
        { < 3,  0,  0>, < 4,  0,  0>, < 5,  0,  0>, < 6,  0,  0> },
        { < 3,  0,  1>, < 4, -1,  1>, < 5, -1,  1>, < 6,  0,  1> },
        { < 3,  0,  2>, < 4, -1,  2>, < 5, -1,  2>, < 6,  0,  2> },
        { < 3,  0,  3>, < 4,  0,  3>, < 5,  0,  3>, < 6,  0,  3> }
      }
    },
    {
      {
        { < 0,  0,  3>, < 1,  0,  3>, < 2,  0,  3>, < 3,  0,  3> },
        { < 0,  0,  4>, < 1, -1,  4>, < 2, -1,  4>, < 3,  0,  4> },
        { < 0,  0,  5>, < 1, -1,  5>, < 2, -1,  5>, < 3,  0,  5> },
        { < 0,  0,  6>, < 1,  0,  6>, < 2,  0,  6>, < 3,  0,  6> }
      },
      {
        { < 3,  0,  3>, < 4,  0,  3>, < 5,  0,  3>, < 6,  0,  3> },
        { < 3,  0,  4>, < 4,  1,  4>, < 5,  1,  4>, < 6,  0,  4> },
        { < 3,  0,  5>, < 4,  1,  5>, < 5,  1,  5>, < 6,  0,  5> },
        { < 3,  0,  6>, < 4,  0,  6>, < 5,  0,  6>, < 6,  0,  6> }
      }
    }
  }



#declare PatchTextures =

  array[PatchesInHeight][PatchesInWidth] {
    {

      texture {
        pigment {
          checker
          color rgbf <1.0, 1.0, 1.0, 0.6>
          color rgbf <0.0, 0.0, 0.0, 0.6>

        }
      },
      texture {
        pigment {
          checker
          color rgbf <0.7, 0.0, 0.0, 0.6>
          color rgbf <1.0, 1.0, 1.0, 0.6>
        }
      }
    },
    {
      texture {
        pigment {
          checker
          color rgbf <0.0, 0.7, 0.0, 0.6>
          color rgbf <1.0, 1.0, 1.0, 0.6>
        }
      },
      texture {
        pigment {
          checker
          color rgbf <1.0, 1.0, 1.0, 0.6>
          color rgbf <0.0, 0.0, 0.7, 0.6>
        }
      }
    }
  }

#declare CntH = 0;
#while (CntH < PatchesInHeight)
  #declare CntW = 0;
  #while (CntW < PatchesInWidth)

    bicubic_patch {
      type 1
      flatness 0.001
      u_steps 4
      v_steps 4
      uv_vectors
        <0, 0>
        <1, 0>
        <1, 1>
        <0, 1>

      #declare I = 0;
      #while (I < 4)
        #declare J = 0;
        #while (J < 4)
          PatchPoints[CntH][CntW][I][J]
          #declare J = J + 1;
        #end // while
        #declare I = I + 1;
      #end // while

      uv_mapping
        texture {
          PatchTextures[CntH][CntW]
          scale 1/3
        }
    }

    #declare CntW = CntW + 1;
  #end // while
  #declare CntH = CntH + 1;
#end // while

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

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

camera {
  location <3, 6, -3>
  look_at <3, 0, 3>
}

light_source {
  500*<1,  1, -1>
  color rgb <1, 1, 1>
  shadowless
}

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


Post a reply to this message

From: D103
Subject: Re: Array of points for use with bicubic patch
Date: 27 Apr 2011 08:05:00
Message: <web.4db805432d1676e49f865aaa0@news.povray.org>
"Tor Olav Kristensen" <tor### [at] TOBEREMOVEDgmailcom> wrote:
>
> Have a look at the code below.
>
> Tor Olav
>
> // ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
>
> #version 3.6;
>
> // ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
>
> #declare PatchesInWidth = 2;
> #declare PatchesInHeight = 2;
>
> #declare PatchPoints =
>   array[PatchesInHeight][PatchesInWidth][4][4] {
>     {
>       {
>         { < 0,  0,  0>, < 1,  0,  0>, < 2,  0,  0>, < 3,  0,  0> },
>         { < 0,  0,  1>, < 1,  1,  1>, < 2,  1,  1>, < 3,  0,  1> },
>         { < 0,  0,  2>, < 1,  1,  2>, < 2,  1,  2>, < 3,  0,  2> },
>         { < 0,  0,  3>, < 1,  0,  3>, < 2,  0,  3>, < 3,  0,  3> }
>       },
>       {
>         { < 3,  0,  0>, < 4,  0,  0>, < 5,  0,  0>, < 6,  0,  0> },
>         { < 3,  0,  1>, < 4, -1,  1>, < 5, -1,  1>, < 6,  0,  1> },
>         { < 3,  0,  2>, < 4, -1,  2>, < 5, -1,  2>, < 6,  0,  2> },
>         { < 3,  0,  3>, < 4,  0,  3>, < 5,  0,  3>, < 6,  0,  3> }
>       }
>     },
>     {
>       {
>         { < 0,  0,  3>, < 1,  0,  3>, < 2,  0,  3>, < 3,  0,  3> },
>         { < 0,  0,  4>, < 1, -1,  4>, < 2, -1,  4>, < 3,  0,  4> },
>         { < 0,  0,  5>, < 1, -1,  5>, < 2, -1,  5>, < 3,  0,  5> },
>         { < 0,  0,  6>, < 1,  0,  6>, < 2,  0,  6>, < 3,  0,  6> }
>       },
>       {
>         { < 3,  0,  3>, < 4,  0,  3>, < 5,  0,  3>, < 6,  0,  3> },
>         { < 3,  0,  4>, < 4,  1,  4>, < 5,  1,  4>, < 6,  0,  4> },
>         { < 3,  0,  5>, < 4,  1,  5>, < 5,  1,  5>, < 6,  0,  5> },
>         { < 3,  0,  6>, < 4,  0,  6>, < 5,  0,  6>, < 6,  0,  6> }
>       }
>     }
>   }
>
>
>
> #declare PatchTextures =
>
>   array[PatchesInHeight][PatchesInWidth] {
>     {
>
>       texture {
>         pigment {
>           checker
>           color rgbf <1.0, 1.0, 1.0, 0.6>
>           color rgbf <0.0, 0.0, 0.0, 0.6>
>
>         }
>       },
>       texture {
>         pigment {
>           checker
>           color rgbf <0.7, 0.0, 0.0, 0.6>
>           color rgbf <1.0, 1.0, 1.0, 0.6>
>         }
>       }
>     },
>     {
>       texture {
>         pigment {
>           checker
>           color rgbf <0.0, 0.7, 0.0, 0.6>
>           color rgbf <1.0, 1.0, 1.0, 0.6>
>         }
>       },
>       texture {
>         pigment {
>           checker
>           color rgbf <1.0, 1.0, 1.0, 0.6>
>           color rgbf <0.0, 0.0, 0.7, 0.6>
>         }
>       }
>     }
>   }
>
> #declare CntH = 0;
> #while (CntH < PatchesInHeight)
>   #declare CntW = 0;
>   #while (CntW < PatchesInWidth)
>
>     bicubic_patch {
>       type 1
>       flatness 0.001
>       u_steps 4
>       v_steps 4
>       uv_vectors
>         <0, 0>
>         <1, 0>
>         <1, 1>
>         <0, 1>
>
>       #declare I = 0;
>       #while (I < 4)
>         #declare J = 0;
>         #while (J < 4)
>           PatchPoints[CntH][CntW][I][J]
>           #declare J = J + 1;
>         #end // while
>         #declare I = I + 1;
>       #end // while
>
>       uv_mapping
>         texture {
>           PatchTextures[CntH][CntW]
>           scale 1/3
>         }
>     }
>
>     #declare CntW = CntW + 1;
>   #end // while
>   #declare CntH = CntH + 1;
> #end // while
>
> // ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
>
> background {
>   color rgb 0.5*<1, 1, 1>
> }
>
> camera {
>   location <3, 6, -3>
>   look_at <3, 0, 3>
> }
>
> light_source {
>   500*<1,  1, -1>
>   color rgb <1, 1, 1>
>   shadowless
> }
>
> // ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

That's great! Took me a while to understand the nested loops though.
Thank you very much.

The other reason I posted was to ask if there was a way to reduce the process of
creating the vectors for the patches to a while loop or nested loops.

Call me lazy, but I'm always looking for shorter/easier ways to do things. :)

D103


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: Array of points for use with bicubic patch
Date: 27 Apr 2011 09:20:00
Message: <web.4db816822d1676e447ba06bb0@news.povray.org>
"D103" <nomail@nomail> wrote:
....
> The other reason I posted was to ask if there was a way to reduce the process of
> creating the vectors for the patches to a while loop or nested loops.
>
> Call me lazy, but I'm always looking for shorter/easier ways to do things. :)

Coding in order to being able to be lazy later is a good thing.
Being lazy while coding is a bad thing.

- And yes, there are ways to do what you want.

Perhaps these 2 images will give you some hints or ideas:

http://home.online.no/~t-o-k/POV-Ray_Images/Bezier_Patches_Stitched.jpg
http://home.online.no/~t-o-k/POV-Ray_Images/Bezier_Patches_Stitched_.jpg

--
Tor Olav
http://subcube.com


Post a reply to this message

From: D103
Subject: Re: Array of points for use with bicubic patch
Date: 3 May 2011 08:40:00
Message: <web.4dbff7222d1676e4dd10c23d0@news.povray.org>
"D103" <nomail@nomail> wrote:
.....
> The other reason I posted was to ask if there was a way to reduce the process of
> creating the vectors for the patches to a while loop or nested loops.
.....
>
> D103

After some experimentation, I have come up with these loops.
The idea is of course, to replace the sphere with an array or to place the loops
within an array, whatever is necessary.

#declare X1=-1.5;  //in the scene file these are equal to the v_length of the
appropriate values.
#declare Z1=-1.5;
#declare Cnt=0;

#while(X1<=1.5)
  #while(Z1<=1.5)
    #if(Cnt>=15)
      #debug "Cnt = illegal value.\n"
    #else
      #debug "Cnt is within legal range.\n"
    #end
    //#declare Pts[Cnt]=<X1, 0, Z1>;
    sphere { 0, 0.1 pigment { White } translate <X1, 0, Z1> }
    #declare Z1=Z1+1;
    #declare Cnt=Cnt+1;
  #end

For some reason, when I run this in POV-Ray, it only creates one sphere, (or
else several spheres in the same location), and when the sphere is replace with
an array, the first point is generated alright, but on the second loop, it
produces an error message: "attempt to access uninitialized array element".
  #declare X1=X1+1;
  #declare Z1=-1.5;
#end

If someone could point out the problem(s), I would be very grateful.

Thanks,
D103


Post a reply to this message

From: Warp
Subject: Re: Array of points for use with bicubic patch
Date: 3 May 2011 11:20:04
Message: <4dc01d24@news.povray.org>
D103 <nomail@nomail> wrote:
> #declare X1=-1.5;  //in the scene file these are equal to the v_length of the
> appropriate values.
> #declare Z1=-1.5;
> #declare Cnt=0;

> #while(X1<=1.5)
>   #while(Z1<=1.5)
>     #if(Cnt>=15)
>       #debug "Cnt = illegal value.\n"
>     #else
>       #debug "Cnt is within legal range.\n"
>     #end
>     //#declare Pts[Cnt]=<X1, 0, Z1>;
>     sphere { 0, 0.1 pigment { White } translate <X1, 0, Z1> }
>     #declare Z1=Z1+1;
>     #declare Cnt=Cnt+1;
>   #end
>   #declare X1=X1+1;
>   #declare Z1=-1.5;
> #end

  You seem to have very complicated ways of performing nested loops.
What's wrong with the traditional way of doing nested loops? In other
words:

#declare Cnt = 0;
#declare X1 = -1.5;
#while(X1 <= 1.5)
  #declare Z1 = -1.5;
  #while(Z1 <= 1.5)

    ...

    #declare Z1 = Z1 + 1;
    #declare Cnt = Cnt + 1;
  #end
  #declare X1 = X1 + 1;
#end

-- 
                                                          - Warp


Post a reply to this message

Goto Latest 10 Messages Next 5 Messages >>>

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