POV-Ray : Newsgroups : povray.newusers : Beginners code doesn't run Server Time
27 Dec 2024 11:11:27 EST (-0500)
  Beginners code doesn't run (Message 1 to 3 of 3)  
From: Markus
Subject: Beginners code doesn't run
Date: 1 Sep 2016 15:55:00
Message: <web.57c88751cc9c34c2412d2b10@news.povray.org>
I try to calculate a mesh2 with math functions. I can't get the code to run. It
stops at the bracket } of the vertex_vectors statement (after the #debug
statement). Probably I do a beginners error. Can you help me?

Here the code:

//
// Meash2test
//

//


#version 3.7;

#include "colors.inc"    // The include files contain
#include "stones.inc"    // pre-defined scene elements

  background { color Cyan }

  light_source { <2, 4, -3> color White}

#declare r = 7;
#declare phi = -1.5;


  camera {
    location <r*cos(phi), 1, r*sin(phi)>
    look_at  <0, 1,  2>
  }


#declare n = 3;
#declare m = 3;
#declare vec = n * m;
#declare f = 2 * (n - 1) * (m - 1);

#declare r = 0.2;
#declare phi = 3.14 / 10;

mesh2 {
    vertex_vectors {
        vec

#declare i = 0;
#declare j = 0;
#while(i<n)
    #while(j<m)
        #declare x1 = pow(i*r,5) * cos(5 * j * phi) - i * r * cos(j * phi);
        #declare y1 = pow(i * r,5) * sin(5 * j * phi) - i * r * sin(j * phi);
        #declare z1 = i*r + j*phi;

        ,<x1,y1,z1>

        #declare j = j + 1;
    #end
    #declare i = i + 1;
#end

#debug concat("i=",str(i,0,0), "  j=",str(j,0,0))
    }
    face_indices {
        f

#declare i = 1;
#declare j = 0;
#while(i < n)
    #while(j < m)
        #declare k = i * n + j;
        #declare k1 = k - m;
        #declare k2 = k - m + 1;
        #declare k3 = k + 1;

        ,<k,k1,k2>, <k, k2, k3>


        #declare j = j + 1;
    #end
    #declare i = i + 1;
#end

    }
    pigment {rgb 1}
}


Post a reply to this message

From: clipka
Subject: Re: Beginners code doesn't run
Date: 1 Sep 2016 16:02:12
Message: <57c88944$1@news.povray.org>
Am 01.09.2016 um 21:54 schrieb Markus:

>     vertex_vectors {
>         vec
> 
> #declare i = 0;
> #declare j = 0;
> #while(i<n)

you want to move the "#declare j = 0" into the outer loop.

>     #while(j<m)
>         #declare x1 = pow(i*r,5) * cos(5 * j * phi) - i * r * cos(j * phi);
>         #declare y1 = pow(i * r,5) * sin(5 * j * phi) - i * r * sin(j * phi);
>         #declare z1 = i*r + j*phi;
> 
>         ,<x1,y1,z1>
> 
>         #declare j = j + 1;
>     #end
>     #declare i = i + 1;
> #end 

Also, presuming you are using POV-Ray 3.7, to avoid such mistakes you
can instead use the `#for` statement, which initializes and increments
the variable automatically.

#for(i,0,n-1)
  #for(j,0,m-1)
    ...
  #end
#end


Post a reply to this message

From: Markus
Subject: Re: Beginners code doesn't run
Date: 2 Sep 2016 02:30:00
Message: <web.57c91c64786d177f4066f2170@news.povray.org>
clipka <ano### [at] anonymousorg> wrote:
> Am 01.09.2016 um 21:54 schrieb Markus:
>
> >     vertex_vectors {
> >         vec
> >
> > #declare i = 0;
> > #declare j = 0;
> > #while(i<n)
>
> you want to move the "#declare j = 0" into the outer loop.
>
> >     #while(j<m)
> >         #declare x1 = pow(i*r,5) * cos(5 * j * phi) - i * r * cos(j * phi);
> >         #declare y1 = pow(i * r,5) * sin(5 * j * phi) - i * r * sin(j * phi);
> >         #declare z1 = i*r + j*phi;
> >
> >         ,<x1,y1,z1>
> >
> >         #declare j = j + 1;
> >     #end
> >     #declare i = i + 1;
> > #end
>
> Also, presuming you are using POV-Ray 3.7, to avoid such mistakes you
> can instead use the `#for` statement, which initializes and increments
> the variable automatically.
>
> #for(i,0,n-1)
>   #for(j,0,m-1)
>     ...
>   #end
> #end

Thanks, this helped :-)


Post a reply to this message

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