POV-Ray : Newsgroups : povray.general : Probably simple ... : Re: Probably simple ... Server Time
8 Aug 2024 01:17:43 EDT (-0400)
  Re: Probably simple ...  
From: Chris Huff
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

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