POV-Ray : Newsgroups : povray.general : A macro that drops a vector-- what's the syntax again? Server Time
29 Nov 2024 11:35:23 EST (-0500)
  A macro that drops a vector-- what's the syntax again? (Message 1 to 10 of 14)  
Goto Latest 10 Messages Next 4 Messages >>>
From: Greg M  Johnson
Subject: A macro that drops a vector-- what's the syntax again?
Date: 9 Nov 2005 21:58:46
Message: <4372b765@news.povray.org>
I cannot get the following code to work:

//-----------------------------
#macro sign(a)
#if (a<0)
        (-a)
#else
        (a)
#end
#end


#macro ease_in(your_clock,your_array)
        #local rotdim=dimension_size(your_array,1);
        #local ennn=0;
        #while(ennn<rotdim)                          
                #if(your_array[ennn].x=your_clock)                     
                                
(<your_array[ennn].y,your_array[ennn].z,your_array[ennn].t>)            
                        
                        #declare ennn=ennn+1e7;                        
                #else                        
                        #if(your_array[ennn].x<your_clock) 
                                #local ennn=ennn+1;
                        #else
                                #local why1=your_array[ennn+0];
                                #local why0=your_array[ennn-1]; 
                                #local
teee=(your_clock-why0.x)/(why1.x-why0.x);
                                #local
teeecubes=0.5-0.5*pow(abs(cos(teee*pi)),0.5)*sign(cos(teee*pi));
                                
                                #local
exxx=why0.y+(why1.y-why0.y)*teeecubes;
                                #local
eyyy=why0.z+(why1.z-why0.z)*teeecubes;
                                #local
ezzz=why0.t+(why1.t-why0.t)*teeecubes;
                        
                                #declare ennn=ennn+1e7;  
                                (<exxx,eyyy,ezzz>)                      
                        
                        #end 
                #end
        #end                 
        
#end

#declare ary=array[3]{
//an array of four dimensions:
//< time,  x_position[n], y_position[n], z_position[n]>

<0.00,     -16,47,24>,
<0.50,      0,52,-0>,
<1.00,     -16,47,24>
}

//sorry for the mess here!
#declare ltempwristpt=<0,0,0>+(ease_in(clock,ary));

sphere{ltempwristpt,1 pigment{red 1}}


Post a reply to this message

From: Slime
Subject: Re: A macro that drops a vector-- what's the syntax again?
Date: 10 Nov 2005 00:36:05
Message: <4372dc45@news.povray.org>
> #macro sign(a)
> #if (a<0)
>         (-a)
> #else
>         (a)
> #end
> #end

#macro sign(a)
    #if (a < 0)
        #local Ans = -a;
    #else
        #local Ans = a;
    #end
    (Ans)
#end

A similar solution for your other macro.

(Though isn't there a sign function or something like that already?)

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


Post a reply to this message

From: kurtz le pirate
Subject: Re: A macro that drops a vector-- what's the syntax again?
Date: 10 Nov 2005 01:01:53
Message: <kurtzlepirate-B61563.07015210112005@news.povray.org>
In article <4372b765@news.povray.org>,
 "Greg M. Johnson" <p t e r a n d o n @ 
 thecommononethatstartswithY.com> wrote:

::I cannot get the following code to work:
::
:://-----------------------------
::#macro sign(a)
::#if (a<0)
::        (-a)
::#else
::        (a)
::#end
::#end

... abs() already exist in pov


Post a reply to this message

From: Zeger Knaepen
Subject: Re: A macro that drops a vector-- what's the syntax again?
Date: 10 Nov 2005 05:56:22
Message: <43732756$1@news.povray.org>
"kurtz le pirate" <kur### [at] yahoofr> wrote in message 
news:kurtzlepirate-B61563.07015210112005@news.povray.org...
> In article <4372b765@news.povray.org>,
>  "Greg M. Johnson" <p t e r a n d o n @ 
>  thecommononethatstartswithY.com> wrote:
> 
> ::I cannot get the following code to work:
> ::
> :://-----------------------------
> ::#macro sign(a)
> ::#if (a<0)
> ::        (-a)
> ::#else
> ::        (a)
> ::#end
> ::#end
> 
> ... abs() already exist in pov

what's abs() got to do with sign(), except that you can make sign() with 
sign(x)=x/abs(x) ?

cu!
-- 
#macro G(b,e)b+(e-b)*C/50#end#macro _(b,e,k,l)#local C=0;#while(C<50)
sphere{G(b,e)+3*z.1pigment{rgb G(k,l)}finish{ambient 1}}#local C=C+1;
#end#end _(y-x,y,x,x+y)_(y,-x-y,x+y,y)_(-x-y,-y,y,y+z)_(-y,y,y+z,x+y)
_(0x+y.5+y/2x)_(0x-y.5+y/2x)            // ZK http://www.povplace.com


Post a reply to this message

From: Warp
Subject: Re: A macro that drops a vector-- what's the syntax again?
Date: 10 Nov 2005 11:57:46
Message: <43737c09@news.povray.org>
Zeger Knaepen <zeg### [at] povplacecom> wrote:
> what's abs() got to do with sign(), except that you can make sign() with
sign(x)=x/abs(x) ?

  Look at his "sign" implementation. It's abs().

-- 
                                                          - Warp


Post a reply to this message

From: John VanSickle
Subject: Re: A macro that drops a vector-- what's the syntax again?
Date: 10 Nov 2005 19:14:32
Message: <4373e268@news.povray.org>
Zeger Knaepen wrote:

> "kurtz le pirate" <kur### [at] yahoofr> wrote in message
news:kurtzlepirate-B61563.07015210112005@news.povray.org...
> 
>>In article <4372b765@news.povray.org>,
>> "Greg M. Johnson" <p t e r a n d o n @ 
>> thecommononethatstartswithY.com> wrote:
>>
>>::I cannot get the following code to work:
>>::
>>:://-----------------------------
>>::#macro sign(a)
>>::#if (a<0)
>>::        (-a)
>>::#else
>>::        (a)
>>::#end
>>::#end
>>
>>... abs() already exist in pov
> 
> 
> what's abs() got to do with sign(), except that you can make sign() with
sign(x)=x/abs(x) ?

With a divide-by-zero error when x==0.

Regards,
John


Post a reply to this message

From: John VanSickle
Subject: Has this bug been reported?
Date: 11 Nov 2005 17:32:03
Message: <43751be3$1@news.povray.org>
Greg M. Johnson wrote:

> I cannot get the following code to work:
> 
> //-----------------------------
> #macro sign(a)
> #if (a<0)
>         (-a)
> #else
>         (a)
> #end
> #end

I've noticed that this way of using macros to express things leads to 
parse errors.  There is a work-around (which has already been posted), 
but the docs give no reason for this construction to fail.  Is this 
behavior deemed worthy of correction?

Regards,
John


Post a reply to this message

From: Thorsten Froehlich
Subject: Re: Has this bug been reported?
Date: 11 Nov 2005 18:12:00
Message: <43752540$1@news.povray.org>
John VanSickle wrote:
> Greg M. Johnson wrote:
> 
>> I cannot get the following code to work:
>>
>> //-----------------------------
>> #macro sign(a)
>> #if (a<0)
>>         (-a)
>> #else
>>         (a)
>> #end
>> #end
> 
> I've noticed that this way of using macros to express things leads to 
> parse errors.  There is a work-around (which has already been posted), 
> but the docs give no reason for this construction to fail.

Well, they do, but I agree it could be a lot clearer.  In "Are POV-Ray 
Macros a Function or a Macro?" it explains it:

"When the body of a macro consists of statements that create an entire item 
such as an object, texture, etc. then the macro acts like a function which 
returns a single value."

The "statements that create an entire item" is the important part here. What 
the macro above is are *two* statements that create *two* items.  Basically, 
the word "item" means what is best explained as "evereything you could also 
assign to a single #declared variable".

> Is this behavior deemed worthy of correction?

It is correct, and it is also possible to obey the "one statement" rule! :-) 
  It just requires slightly different syntax:

#macro sign(a)
(
#if (a<0)
         -a
#else
         a
#end
);
#end

is perfectly legal!

	Thorsten


Post a reply to this message

From: Greg M  Johnson
Subject: Re: A macro that drops a vector-- what's the syntax again?
Date: 11 Nov 2005 21:40:16
Message: <43755610@news.povray.org>
Greg M. Johnson wrote:


 Oi vey!  Too much late-night coding, I guess.  :-S

Yes, that's an abs() function.  I wanted a sign() function and so was
writing my own.

Perhaps it was late-night delusions, but I did think that povray 3.5 (the
apt-get version) was freaking with me when it came to nested function/macro
calls. 


> I cannot get the following code to work:
> 
> //-----------------------------
> #macro sign(a)
> #if (a<0)
>         (-a)
> #else
>         (a)
> #end
> #end


Post a reply to this message

From: Warp
Subject: Re: Has this bug been reported?
Date: 12 Nov 2005 03:09:05
Message: <4375a321@news.povray.org>
John VanSickle <evi### [at] hotmailcom> wrote:
> I've noticed that this way of using macros to express things leads to 
> parse errors.  There is a work-around (which has already been posted), 
> but the docs give no reason for this construction to fail.  Is this 
> behavior deemed worthy of correction?

  The documentation could be clearer. It's difficult to explain clearly,
though. Any suggestions?
  The behaviour itself is logical, but not easy to explain.

-- 
                                                          - Warp


Post a reply to this message

Goto Latest 10 Messages Next 4 Messages >>>

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