POV-Ray : Newsgroups : povray.advanced-users : Vector Components Server Time
28 Jul 2024 18:16:39 EDT (-0400)
  Vector Components (Message 1 to 6 of 6)  
From: nomail
Subject: Vector Components
Date: 15 Sep 2004 16:05:01
Message: <web.4148a03fe2a5f8e58b2587f70@news.povray.org>
I am trying to make a function which uses a vector cordnate return a value.
Within this the I am trying to pull the y component of the input to do a
compareson on it.  I have tried with both #if and #switch and have the same
problem.

#declare MyFn = function {
  #switch ( y )
    #case ( 1 )
      // funcion code 1
    #break // 1
    #case ...
  #end // switch
}

Parse Error: Float expected but vector or color expression found.

Is there a vector function I can use to get they y component, MyFn.y, <y> or
such?

-=<{()}>=-

 Thorcane

-=<{()}>=-


Post a reply to this message

From: Andrew C on Mozilla
Subject: Re: Vector Components
Date: 15 Sep 2004 16:09:25
Message: <4148a175@news.povray.org>
> #declare MyFn = function {
>   #switch ( y )
>     #case ( 1 )
>       // funcion code 1
>     #break // 1
>     #case ...
>   #end // switch
> }
> 
> Parse Error: Float expected but vector or color expression found.
> 
> Is there a vector function I can use to get they y component, MyFn.y, <y> or
> such?

Hmm... that's not gonna work.

The #switch executes at parse time, whereas the rest of the function 
executes at trace time. In other words, you can use a switch that 
depends on a constant defined somewhere else (e.g., animation frame 
number), but *not* on a parameter to the function.

(The exact error you're seeing is because "y" has two meanings in 
POV-Ray. Usually y = <0, 1, 0> - *except* inside functions, where "y" 
suddenly means the 2nd parameter to the function. But only at trace 
time, not parse time. Confused? POV-Ray is!)

Andrew @ home.


Post a reply to this message

From: nomail
Subject: Re: Vector Components
Date: 15 Sep 2004 16:30:00
Message: <web.4148a5d120945ceb8b2587f70@news.povray.org>
> Hmm... that's not gonna work.

Not exactly what I wanted to hear.  I guess I will have to work out a new
function  to do what I wanted.

Thank you.  If anyone has any suggestions to make the original work please
feel free to post.

-=<{()}>=-
 Thorcane
-=<{()}>=-


Post a reply to this message

From: Slime
Subject: Re: Vector Components
Date: 15 Sep 2004 17:24:07
Message: <4148b2f7$1@news.povray.org>
You should read the thread "How to get a texture like (y>0.8 & z>0.9) ->
texture a      else -> texture= b?" by D. H. Berlin in povray.newusers on
9/3/2004 11:23 AM. He had a nearly identical problem. The solution is
probably the select() function.

 - Slime
 [ http://www.slimeland.com/ ]


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: Vector Components
Date: 15 Sep 2004 17:31:49
Message: <4148b4c5$1@news.povray.org>
nomail@nomail wrote:

>>Hmm... that's not gonna work.
> 
> 
> Not exactly what I wanted to hear.  I guess I will have to work out a new
> function  to do what I wanted.
> 
> Thank you.  If anyone has any suggestions to make the original work please
> feel free to post.

I suggest that you read about about user defined functions and
the select() function.

2.2.1.6.3 Declaring User-Defined Float Functions:
http://www.povray.org/documentation/view/3.6.1/231/

2.2.1.3.4 Functions:
http://www.povray.org/documentation/view/3.6.1/228/

Here's a simple example:

#declare MyFn =
   function(x, y, z) {                         // Or just: function { 

     select(y - 1, 0, SomeExpression, 0)  +    // Case: y = 1
     select(y - 2, 0, OtherExpression, 0) +    // Case: y = 2
     select(y - 2, 0, 0, YetAnotherExpression) // Case: y > 2
   }

You may also have a look at my reply in this thread in p.b.s-f:
From: Yadgar
Subject: Discontinuous functions?
Date: 14 Aug 2004 11:19:55

http://tinyurl.com/6vaar
http://news.povray.org/povray.binaries.scene-files/message/%3C411fd33c%40news.povray.org%3E/#%3C411fd33c%40news.povray.org%3E

-- 
Tor Olav
http://subcube.net
http://subcube.com


Post a reply to this message

From: Andrew C on Mozilla
Subject: Re: Vector Components
Date: 22 Sep 2004 14:45:50
Message: <4151c85e@news.povray.org>
>>> Hmm... that's not gonna work.
>>
>>
>>
>> Not exactly what I wanted to hear.  I guess I will have to work out a new
>> function  to do what I wanted.
> 
> I suggest that you read about about user defined functions and
> the select() function.

Ah... I forgot about this. Yes, that would seem to be the answer. (I was 
trying to construct something using the abs() and sign() functions to 
achieve the same result...)

Andrew @ home.


Post a reply to this message

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