POV-Ray : Newsgroups : povray.newusers : Two meanings of x? Server Time
27 Nov 2024 02:53:12 EST (-0500)
  Two meanings of x? (Message 1 to 7 of 7)  
From: Dave Matthews
Subject: Two meanings of x?
Date: 5 Aug 2003 14:45:01
Message: <web.3f2ff7b7cfc89a807196f5900@news.povray.org>
I'm not exactly a new user, but this is definitely a basic new-user type
question, and the answer is probably in the manual, but I have been pouring
over it off and on for a few months and am still confused on this basic
point.  Please be kind in your response.

In section 6.1.4.5, we learn that x, y, z, t, u, and v are constants, i.e.,
standard unit basis vectors.  x = <1, 0, 0>, etc.

Yet, inside a function, x is not a constant, but a variable, i.e. the
x-component of "something."  I can define a function in an isosurface with
function { y - x*x + z*z} and x, y and z are definitely not the unit basis
vectors in this interpretation.  In fact, I can usually get by with just
thinking of them as the co-ordinates of a point in 3D space.

Here's where my problem comes in.  Suppose I want to define a multi-rule
function:

In regular math, if x, y, and z were just points in space, I could say:

function{ #if (x < 0 ) whatever },

but, of course, in POVRay, I get an error, since here x is interpreted as
the standard unit basis vector <1, 0, 0>, even though in the function
description that follows, x is evaluated as a float variable (I'm not a
programmer, so "float variable" is probably the wrong term, but I hope you
know what I mean.)

So I guess my question has three parts:

1.  If, inside a function, x, y and z are components of some vector, what's
the name of the vector?  (So I can do a myvector.x in the #if statement.)

2.  If they aren't, and I'm all messed up, can you straighten me out, or
point me to the place in the manual that explains this (since these things
are all usually explained somewhere in the manual, but I'm often blind when
looking)?

3.  If questions #1 and #2 make no sense, could someone tell me how to
reference x, y and z with #if statements inside a function, and maybe when
I see the correct syntax I'll figure out what's wrong with my thinking.
Like, how would I make a function that gives me, for example, x*x + y*y +
z*z - 4 if sin(x + y) < z and x*x - y*y otherwise (just to pull an example
out of thin air.)

I know getting an inane question like this, after all the work you put into
the manual, must be frustrating, but I'm at a loss here, and I need
straightening out.

Thanks

Dave Matthews


Post a reply to this message

From: ABX
Subject: Re: Two meanings of x?
Date: 5 Aug 2003 14:55:34
Message: <h4vvivoqml30opn7ro2qcoovk6j8igve4c@4ax.com>
On Tue,  5 Aug 2003 14:36:51 EDT, "Dave Matthews" <mat### [at] dinecollegeedu>
wrote:
> 1.  If, inside a function, x, y and z are components of some vector, what's
> the name of the vector?  (So I can do a myvector.x in the #if statement.)

Instead of writing:

  function{MyVector.x + 1}

you can write something like:

  #local MyX=MyVector.x;
  function{MyX + 1}

ABX


Post a reply to this message

From: Christopher James Huff
Subject: Re: Two meanings of x?
Date: 5 Aug 2003 15:12:11
Message: <cjameshuff-118111.14103705082003@netplex.aussie.org>
In article <web.3f2ff7b7cfc89a807196f5900@news.povray.org>,
 "Dave Matthews" <mat### [at] dinecollegeedu> wrote:

> 1.  If, inside a function, x, y and z are components of some vector, what's
> the name of the vector?  (So I can do a myvector.x in the #if statement.)

It has no name. The x, y, and z values are float parameters to the 
function. And you seem to expect the #if() statement to execute when the 
function is run...it won't, it will execute when the function is defined.

#declare Test = true;

function {
    #if(Test)
        x*x + z*z
    #else
        y*y + z*z
    #end
}

Is equivalent to:

function {x*x + z*z}


> 3.  If questions #1 and #2 make no sense, could someone tell me how to
> reference x, y and z with #if statements inside a function, and maybe when
> I see the correct syntax I'll figure out what's wrong with my thinking.
> Like, how would I make a function that gives me, for example, x*x + y*y +
> z*z - 4 if sin(x + y) < z and x*x - y*y otherwise (just to pull an example
> out of thin air.)

Look at the documentation for the select() function.

-- 
Christopher James Huff <cja### [at] earthlinknet>
http://home.earthlink.net/~cjameshuff/
POV-Ray TAG: chr### [at] tagpovrayorg
http://tag.povray.org/


Post a reply to this message

From: Dave Matthews
Subject: Re: Two meanings of x?
Date: 5 Aug 2003 15:30:01
Message: <web.3f30053928b286237196f5900@news.povray.org>
Christopher James Huff wrote:

>It has no name. The x, y, and z values are float parameters to the
>function. And you seem to expect the #if() statement to execute when the
>function is run...it won't, it will execute when the function is defined.
>
>#declare Test = true;
>
>function {
>    #if(Test)
>        x*x + z*z
>    #else
>        y*y + z*z
>    #end
>}
>
>Is equivalent to:
>
>function {x*x + z*z}
>
>
>> 3.  If questions #1 and #2 make no sense, could someone tell me how to
>> reference x, y and z with #if statements inside a function, and maybe when
>> I see the correct syntax I'll figure out what's wrong with my thinking.
>> Like, how would I make a function that gives me, for example, x*x + y*y +
>> z*z - 4 if sin(x + y) < z and x*x - y*y otherwise (just to pull an example
>> out of thin air.)
>
>Look at the documentation for the select() function.
>
>Christopher James Huff <cja### [at] earthlinknet>
>http://home.earthlink.net/~cjameshuff/
>POV-Ray TAG: chr### [at] tagpovrayorg
>http://tag.povray.org/
>

OK.  About a dozen lightbulbs just came on.  When I stop blinking, I'll pour
over the select() function.  Thank you very much.

Your diagnosis "you seem to expect the #if() statement to execute when the
function is run" was absolutely true, and the basis for most of my
confusion.

Thanks again.

Dave Matthews


Post a reply to this message

From: Dave Matthews
Subject: Re: Two meanings of x?
Date: 5 Aug 2003 15:35:01
Message: <web.3f3005cc28b286237196f5900@news.povray.org>
ABX wrote:
>On Tue,  5 Aug 2003 14:36:51 EDT, "Dave Matthews" <mat### [at] dinecollegeedu>
>wrote:
>> 1.  If, inside a function, x, y and z are components of some vector, what's
>> the name of the vector?  (So I can do a myvector.x in the #if statement.)
>
>Instead of writing:
>
>  function{MyVector.x + 1}
>
>you can write something like:
>
>  #local MyX=MyVector.x;
>  function{MyX + 1}
>
>ABX
>
Thanks.  I think you just answered a different question that I had.  My
wording was confusing, but somehow Christopher James Huff saw through my
obfuscation to this particular problem.

Thanks again.

Dave Matthews


Post a reply to this message

From: Warp
Subject: Re: Two meanings of x?
Date: 5 Aug 2003 18:12:14
Message: <3f302bbe@news.povray.org>
Dave Matthews <mat### [at] dinecollegeedu> wrote:
> Your diagnosis "you seem to expect the #if() statement to execute when the
> function is run" was absolutely true, and the basis for most of my
> confusion.

  All #-commands are interpreted when the function is parsed. An 'x' inside
a #-command (such as #if) is the "parse-time x", that is the vector <1,0,0>.
  After the function has been parsed (and byte-compiled to internal format),
no #-commands are seen anymore. Only what was left after the #-commands
were parsed are seen.
  #if is a parsing-time command. select() is a function which is evaluated
at runtime (meaning when the function is called at parse or render time).

  I know, it's a bit difficult to understand and explain...

-- 
plane{-x+y,-1pigment{bozo color_map{[0rgb x][1rgb x+y]}turbulence 1}}
sphere{0,2pigment{rgbt 1}interior{media{emission 1density{spherical
density_map{[0rgb 0][.5rgb<1,.5>][1rgb 1]}turbulence.9}}}scale
<1,1,3>hollow}text{ttf"timrom""Warp".1,0translate<-1,-.1,2>}//  - Warp -


Post a reply to this message

From: Dave Matthews
Subject: Re: Two meanings of x?
Date: 6 Aug 2003 09:55:00
Message: <web.3f3107c128b286237196f5900@news.povray.org>
Warp wrote:
>Dave Matthews <mat### [at] dinecollegeedu> wrote:
>> Your diagnosis "you seem to expect the #if() statement to execute when the
>> function is run" was absolutely true, and the basis for most of my
>> confusion.
>
>  All #-commands are interpreted when the function is parsed. An 'x' inside
>a #-command (such as #if) is the "parse-time x", that is the vector <1,0,0>.
>  After the function has been parsed (and byte-compiled to internal format),
>no #-commands are seen anymore. Only what was left after the #-commands
>were parsed are seen.
>  #if is a parsing-time command. select() is a function which is evaluated
>at runtime (meaning when the function is called at parse or render time).
>
>  I know, it's a bit difficult to understand and explain...
>
>plane{-x+y,-1pigment{bozo color_map{[0rgb x][1rgb x+y]}turbulence 1}}
>sphere{0,2pigment{rgbt 1}interior{media{emission 1density{spherical
>density_map{[0rgb 0][.5rgb<1,.5>][1rgb 1]}turbulence.9}}}scale
><1,1,3>hollow}text{ttf"timrom""Warp".1,0translate<-1,-.1,2>}//  - Warp -
>

Thanks.  That's about what I had figured out after Christopher's
explanation, but this completely clarifies it.  That also explains what
I've been reading about people attempting to create fractal functions using
'select()' --  I couldn't figure out what would be so tough about it just
using #while.... Now I'm beginning to understand (I think.)

And now I can even start using functions and isosurfaces.

Opens up a whole new world;-)


Post a reply to this message

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