POV-Ray : Newsgroups : povray.general : Probably simple ... Server Time
8 Aug 2024 04:07:57 EDT (-0400)
  Probably simple ... (Message 1 to 5 of 5)  
From: ingo
Subject: Probably simple ...
Date: 17 Mar 2001 06:01:20
Message: <Xns90677A8B1A12Dseed7@povray.org>
.. but can't figure it out at the moment.

I'm looking for a macro that returns a value based on an input value 
(Val) within a given input range (iMin to iMax), the ReturnVal has to 
be in the range oMin, oMax. 
Kind of like the "how to create random numbers in a range other than 0 
to 1". But then with a arbitrary input range.

#macro RVal(iMin, iMax, Val, oMin, oMax)
    	.
    	.
    	ReturnVal
#end


Ingo

-- 
Photography: http://members.home.nl/ingoogni/
Pov-Ray    : http://members.home.nl/seed7/


Post a reply to this message

From: Alessandro Coppo
Subject: Re: Probably simple ...
Date: 17 Mar 2001 06:19:54
Message: <3ab3485a@news.povray.org>
ingo wrote in message ...
>I'm looking for a macro that returns a value based on an input value
>(Val) within a given input range (iMin to iMax), the ReturnVal has to
>be in the range oMin, oMax.
>Kind of like the "how to create random numbers in a range other than 0
>to 1". But then with a arbitrary input range.


Here you are:

    #macro RVal(iMin, iMax, Val, oMin, oMax)
        #local v  = (Val - iMin) / (iMax - iMin);


        (oMin + (oMax - oMin) * v)
    #end


The first line gives you a [0,1] value and the second "returns" the result.
E.g.

    #declare qqq = RVal(0., 1., .4, 10, 20);

which expanded becomes:

    #declare qqq = (10 + (20 - 10) * (.4 - 0) / (1 - 0));

(If I got the parenthesis right!!!)

BTW, ALWAYS put between () the return value, otherwise calls like this would
be wrong:

    RVal(....) * 10

which has to be (...) * 10 and NOT oMin + (oMax - oMin) * v *10!

Bye!!!
Alessandro Coppo

P.S: have a look at POVRay documentation, this function call/procedure call
hybrid nature is well explained in #macro help.


Post a reply to this message

From: ingo
Subject: Re: Probably simple ...
Date: 17 Mar 2001 06:40:43
Message: <Xns906781385621Dseed7@povray.org>
in <3ab3485a@news.povray.org> Alessandro Coppo wrote:

>Here you are:
> ...

Thanks

Ingo

-- 
Photography: http://members.home.nl/ingoogni/
Pov-Ray    : http://members.home.nl/seed7/


Post a reply to this message

From: Chris Huff
Subject: Re: Probably simple ...
Date: 17 Mar 2001 10:37:49
Message: <chrishuff-401013.10321817032001@news.povray.org>
In article <3ab3485a@news.povray.org>, "Alessandro Coppo" 
<a.c### [at] iolit> wrote:

> Here you are:
>     #macro RVal(iMin, iMax, Val, oMin, oMax)
>         #local v  = (Val - iMin) / (iMax - iMin);
> 
> 
>         (oMin + (oMax - oMin) * v)
>     #end

Why not simplify it to this?
#macro RVal(iMin, iMax, Val, oMin, oMax)
    (oMin + (oMax - oMin)*((Val - iMin)/(iMax - iMin)))
#end

BTW, here are the macros I use for the same thing:

// Range handling macros
#macro Clamp(V, Min, Max) (min(Max, max(Min, V))) #end
// clamps a number to the range [Min, Max]. Values above Max return Max, 
below Min return Min.

#macro Range(V, Rmn, Rmx) (V*(Rmx-Rmn) + Rmn) #end
// adjusts input values in the range [0, 1] to output values in range 
[Rmn, Rmx].

#macro RRange(V, Rmn, Rmx, Min, Max) (((V-Rmn)/(Rmx-Rmn))*(Rmx-Rmn) + 
Rmn) #end
// adjusts values in a specified range [Rmn, Rmx] to the specified range 
[Min, Max]

-- 
Christopher James Huff
Personal: chr### [at] maccom, http://homepage.mac.com/chrishuff/
TAG: chr### [at] tagpovrayorg, http://tag.povray.org/

<><


Post a reply to this message

From: Alessandro Coppo
Subject: Re: Probably simple ...
Date: 17 Mar 2001 18:50:10
Message: <3ab3f832$1@news.povray.org>
Just to make it immediately readable for...
a) ...everybody besides me and...
b) ...myself in six months time ;-)

Alessandro Coppo
a.c### [at] iolit


Post a reply to this message

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