POV-Ray : Newsgroups : povray.advanced-users : user-defined functions-- basic question of use Server Time: 16 Dec 2018 21:37:44 GMT
 user-defined functions-- basic question of use (Message 1 to 10 of 16)
 From: Kenneth Subject: user-defined functions-- basic question of use Date: 25 Feb 2018 19:20:00 Message:
```I'm familiar with using PIGMENT/PATTERN functions, although it has been awhile.
But I was looking at 3.3.1.8.4 "Declaring User-Defined Vector Functions" in the
docs, and it's not clear to me how to actually *use* the examples given there.

The first example (a transform function) is described only like this:

#declare foo = function {
transform {
rotate <90, 0, 0>
scale 4
}
}

#declare myvector = foo(4, 3, 7);

How is "myvector" supposed to be used? My assumption is that it 'acts like' a
transform-- just like any transform{..}-- but I can't get it to work. Maybe I'm
using it in a totally wrong way? I tried all sorts of permutations in a sphere
object, but NONE of them work-- all fatal errors. (Some of these are probably
nonsense, but I wanted to be thorough.) Can someone give an example of the
correct way to use  myvector-- in a sphere, or in some other way altogether? I'm
obviously not grasping the underlying idea.

sphere{0,.3

// myvector
// or...
//my_vector(4,3,7)
// or...
//transform{myvector}
// or...
//transform{myvector(4,3,7)}
// or...
//transform{myvector(x,y,z)}
// or...
//function{myvector}
// or...
//function(x,y,z){myvector}
// or...
//foo
// or...
//foo(4,3,7)
// or...
//function{foo}
// or...
//function(x,y,z){foo}
// or..
//transform{foo}
// or...
//transform{foo(4,3,7)}
// or...
//transform{ <myvector.x,my-vector.y,myvector.z>}
// or... ??
pigment{ rgb <0,1,0>}
}
```
 From: Bald Eagle Subject: Re: user-defined functions-- basic question of use Date: 25 Feb 2018 22:10:00 Message:
```http://www.f-lohmueller.de/pov_tut/trans/trans_500e.htm

http://www.f-lohmueller.de/pov_tut/trans/trans_000e.htm
```
 From: Ive Subject: Re: user-defined functions-- basic question of use Date: 25 Feb 2018 22:20:51 Message: <5a9336c3\$1@news.povray.org>
```Am 2/25/2018 um 20:18 schrieb Kenneth:
> The first example (a transform function) is described only like this:
>
> #declare foo = function {
>    transform {
>      rotate <90, 0, 0>
>      scale 4
>      }
>    }
>
> #declare myvector = foo(4, 3, 7);
>
> How is "myvector" supposed to be used? My assumption is that it 'acts
like' a
> transform-- just like any transform{..}-- but I can't get it to work.

No, "myvector" (as its name suggest) is just a vector. Its the result of
the vector <4, 3, 7> with the transformation "foo" applied.
In this case it is simple to calculate: <16, -28, 12>

So

sphere {myvector, 0.3
pigment {rgb <0,1,0>}
}

or

sphere {foo(4, 3, 7), 0.3
pigment {rgb <0,1,0>}
}

works and will position the sphere at <16, -28, 12>.
```
 From: Alain Subject: Re: user-defined functions-- basic question of use Date: 26 Feb 2018 00:14:18 Message: <5a93515a@news.povray.org>
```Le 18-02-25 Ã  14:18, Kenneth a Ã©critÂ :
> I'm familiar with using PIGMENT/PATTERN functions, although it has been awhile.
> But I was looking at 3.3.1.8.4 "Declaring User-Defined Vector Functions" in the
> docs, and it's not clear to me how to actually *use* the examples given there.
>
> The first example (a transform function) is described only like this:
>
> #declare foo = function {
>    transform {
>      rotate <90, 0, 0>
>      scale 4
>      }
>    }
>
> #declare myvector = foo(4, 3, 7);
>
> How is "myvector" supposed to be used? My assumption is that it 'acts like' a
> transform-- just like any transform{..}-- but I can't get it to work. Maybe I'm
> using it in a totally wrong way? I tried all sorts of permutations in a sphere
> object, but NONE of them work-- all fatal errors. (Some of these are probably
> nonsense, but I wanted to be thorough.) Can someone give an example of the
> correct way to use  myvector-- in a sphere, or in some other way altogether? I'm
> obviously not grasping the underlying idea.
>

The foo function don't take any paremeter at all.
All function need the parantesis.

So, myvector will always be :
transform{rotate <90,0,0> scale 4}
It shold be named "MyTransform" to have a descriptive name.

The only way that I can think of using that function that should work is :

transform{foo()}

If you apply that to a sphere situated at the origin, the only visible
effect will be to scale it by 4.

Try :
sphere{<0,1,0> 1 transform{foo()}}
```
 From: Kenneth Subject: Re: user-defined functions-- basic question of use Date: 26 Feb 2018 00:25:00 Message:
```Ive <ive### [at] lilysoftorg> wrote:
>
> No, "myvector" (as its name suggest) is just a vector. Its the result of
> the vector <4, 3, 7> with the transformation "foo" applied.
> In this case it is simple to calculate: <16, -28, 12>
>
> So
>
> sphere {myvector, 0.3
>       pigment {rgb <0,1,0>}
> }
>
> or
>
> sphere {foo(4, 3, 7), 0.3
>       pigment {rgb <0,1,0>}
> }
>
> works and will position the sphere at <16, -28, 12>.

Thanks very much; really appreciated. Yes, that was generally *the way* I
thought it would work-- but the example suggests that it's 'a transform', and I
thought that it needed to be used *after* the object is initially made...like a
typical translate, rotate, transform{..} block etc. And not as just *a* vector
itself.

In your opinion (and Bald Eagle's), is the documentation as-is clear enough to
suggest this proper use? I feel like there is some 'explanatory key to
understanding' that is missing there. Perhaps it's the function idea that messes
me up-- not clearly grasping that it produces just a vector (a set of three
values, to be used as such.)
```
 From: Kenneth Subject: Re: user-defined functions-- basic question of use Date: 26 Feb 2018 00:40:01 Message:
```"Bald Eagle" <cre### [at] netscapenet> wrote:
> http://www.f-lohmueller.de/pov_tut/trans/trans_500e.htm

Yep, a trqansform block itself is easy to understand. It's just a 'container' of
stuff to be used later, and applies its ingredients one after the other.
>
> http://www.f-lohmueller.de/pov_tut/trans/trans_000e.htm

YES! That's great, I hadn't seen it. Excellent, and with visual examples as
well. Once again, he has helped clarify some rather difficult POV concepts for
me. RIP.

Just today, I was actually scratching my head about some of those POV vector
transforms (regarding my recent 'chromadepth' code.)

Thanks indeed.
```
 From: Ive Subject: Re: user-defined functions-- basic question of use Date: 26 Feb 2018 09:20:01 Message: <5a93d141@news.povray.org>
```Am 2/26/2018 um 1:21 schrieb Kenneth:
> In your opinion (and Bald Eagle's), is the documentation as-is clear enough to
> suggest this proper use? I feel like there is some 'explanatory key to
> understanding' that is missing there.

Well, it seems clear enough to me, but - having not looked at the docs
myself since decades - I'm the wrong person to ask and my opinion in
this case doesn't matter.
And I know that I suck when it comes down to explaining anything to
somebody else...

-Ive
```
 From: Bald Eagle Subject: Re: user-defined functions-- basic question of use Date: 26 Feb 2018 14:35:01 Message:
```"Kenneth" <kdw### [at] gmailcom> wrote:

> In your opinion (and Bald Eagle's), is the documentation as-is clear enough to
> suggest this proper use? I feel like there is some 'explanatory key to
> understanding' that is missing there.

It's something that I've tried to point out before, in several areas, on several
topics.

A line or two of working code can save 1000 lines of "documentation" and another
week of newsgroup posts trying to figure out the syntax and application.

The documentation isn't too bad _if you already know what you're doing_ , but if
you're a new user trying to do something like this for the first time - it
really almost isn't helpful at all.

Throw a working scene in the distro, or have a few small "blurbs" that DO
something.
The optional macro parameters where "an argument can be omitted" - but you still
need to add in the comma for it, is a good example where it's very hard to
understand that from what's written in the docs.
```
 From: clipka Subject: Re: user-defined functions-- basic question of use Date: 26 Feb 2018 16:10:30 Message: <5a943176@news.povray.org>
```Am 25.02.2018 um 20:18 schrieb Kenneth:
> I'm familiar with using PIGMENT/PATTERN functions, although it has been awhile.
> But I was looking at 3.3.1.8.4 "Declaring User-Defined Vector Functions" in the
> docs, and it's not clear to me how to actually *use* the examples given there.
>
> The first example (a transform function) is described only like this:
>
> #declare foo = function {
>   transform {
>     rotate <90, 0, 0>
>     scale 4
>     }
>   }
>
> #declare myvector = foo(4, 3, 7);
>
> How is "myvector" supposed to be used? My assumption is that it 'acts like' a
> transform-- just like any transform{..}-- but I can't get it to work. Maybe I'm
> using it in a totally wrong way?

You're using it totally wrong indeed: While the function does /apply/ a
transform to the parameters submitted, it /acts/ like a vector when
invoked (namely the vector you'd get if you applied the transform to the
vector corresponding to the three parameter values supplied).

E.g,

#declare T = transform { rotate <90,0,0> scale 4 }
#declare foo = function { transform { T } }
#declare myvector = foo(4,3,7);
sphere { myvector, .3 }

or

#declare T = transform { rotate <90,0,0> scale 4 }
#declare foo = function { transform { T } }
sphere { foo(4,3,7), .3 }

is equivalent to

#declare T = transform { rotate <90,0,0> scale 4 }
sphere { vtransform(<4,3,7>,T), .3 }

If you want something that acts like a transform, you must use a
transform. For example:

#declare T = transform { rotate <90,0,0> scale 4 }
sphere { 0, .3
transform { T }
}
```
 From: Kenneth Subject: Re: user-defined functions-- basic question of use Date: 26 Feb 2018 19:35:01 Message:
```In testing this, I see something worth noting.

First, I'll create what looks like a good analog of the doc's function example
(the way that example's operation might appear to a typical or new-user), but
without any function:

sphere{0,0.3 translate <4,3,7>
transform{
rotate <90,0,0>
scale 4
}
}

And here's Ive's 2nd function-use example (although his 1st works
identically)...
sphere {foo(4, 3, 7), 0.3}

Both of these put the sphere at exactly the same transformed vector location--
but the non-function example scales the size of the sphere by 4, whereas the
function does not.

Of course, I see the obvious reason why the scales are different in these two
constructs-- but the doc's function example would not be clear at all as to the
difference (IMO) without a useful example to demonstrate it. It would depend on
how familiar users are with functions themselves, and what they do. (Would a new
user attempt to create a function at all, lacking any POV-Ray experience? Maybe,
maybe not.)

In fact, the 'SCALE 4' in the doc's transform was one of the nagging little
questions I was wondering about when I originally posted: in what way the
function affected both the new vector AND the sphere size. Of course, I didn't
know how to use it then. ;-)

The documentation can be a funny thing sometimes: The more obvious
features have good explanations and examples, whereas the more abstruse sections
are lacking-- when THEY need it most.
```