|  |  | kurtz le pirate <kur### [at] free fr> wrote:
> Hello,
>
> This exemple come from MathMod, "Vase_3 by Abderrahman Taha 31/10/2019"
>
> Several isosurfaces and functions including these two :
>
> isoTransform_2 =
> if(CarvinCondition(x,y,z,t)=(0),ThickIsoExterior(x,y,z,t),1)"
>
>
isoTransform_6=if(CarvinCondition(x,y,z,t)&ThickIsoExterior(x,y,z,t)<(0),-ThickIso2((6*x),(6*y),(6*z),t)*Iso6((x*6),(
y*6),(z*6),-1)
> *(Iso6((x*6),(y*6),(z*6),1)),1)"
>
> CarvinCondition, ThickIsoExterior, ThickIso2, Iso6 are others functions.
>
>
>
> The (my) transcription for POV gives :
>
> #declare isoTransform_2 = function(x,y,z,T) {
>    select (
>   // A (condition)
>     CarvinCondition(x,y,z,T),
>   // B : A < 0
>      ThickIsoExterior(x,y,z,T),
>     // C : A = 0
>     1,
>     // D : A > 0
>      ThickIsoExterior(x,y,z,T)
>      )
>     }
>
> #declare isoTransform_6 = function(x,y,z,T) {
>  select (
>   // A (condition)
>   (CarvinCondition(x,y,z,T) & ThickIsoExterior(x,y,z,T)),
>   // B : A <0
>   -ThickIso2((6*x),(6*y),(6*z),T) * Iso6((x*6),(y*6),(z*6),-1) *
> (Iso6((x*6),(y*6),(z*6),1)),
>   // C : A >= 0
>     1
>     )
>    }
>
>
> Do you agree with the use of select() to replace if() ?
> I'm struggling a bit and I would like to check this option already.
>
>
>
> On the left is MathMod, on the right where I am.
>...
Hi Kurtz
That's an interesting project.
I found some MathMod documentation here:
https://fossies.org/linux/mathmod/documentation/index.html#SupportedOperatorsFunctions
Some of its mathematical operators in order of precedence:
! A
unary logical not (result is 1 if A is 0, else 0)
A = B    A < B    A <= B    A != B    A > B    A >= B
comparison between A and B (result is either 0 or 1)
A & B
result is 1 if A and B differ from 0, else 0
A | B
result is 1 if A or B differ from 0, else 0
One of its mathematical functions:
if(A, B, C)
if A differs from 0, the return value of this function is B, else C
In POV-Ray 0 = 0.0, so I have removed the all the int() calls in the
expressions above.
From this documentation I understand that any value equal to 0 is treated
as a logical False and any other numerical value is treated as logical True.
(I think this convention makes expressions harder to understand, so I will
not use it further in my simplified expressions, even if POV-Ray also uses it.
Writing readable expressions is more important than writing compact
expressions.)
To make it easier to get an overview, I rename the MathMod functions in your
post, remove their parameter lists and arguments, insert some white space
and finally simplify them a bit.
isoTransform_2(): IT2()
isoTransform_6(): IT6()
CarvinCondition(): CC()
ThickIsoExterior(): TIE()
ThickIso2(): TI2()
Iso6(): I6()
IT2() =
    if(
        CC() = 0,
        TIE(),
        1
    )
IT2() =
    if(
        CC(),
        1,
        TIE()
    )
IT6() =
    if(
        CC() & (TIE() < 0),
        -TI2()*I6()*I6(),
        1
    )
IT6() =
    if(
        TIE() < 0,
        if(
            CC(),
            -TI2()*I6()*I6(),
            1
        ),
        1
    )
The nested ifs above has the same effect as the & operator.
Now a rewrite to POV-Ray expressions is not so difficult:
IT2():
    select(
        CC(),
        1,
        TIE(),
        1
    )
IT6():
    select(
        TIE(),
        select(
            CC(),
            -TI2()*I6()*I6(),
            1,
            -TI2()*I6()*I6()
        ),
        1
    )
The nested selects above has the same effect as the & operator.
Now you can fill in the parameter lists, the arguments, give back functions
their original names and give them a proper POV-Ray function syntax.
--
Tor Olav
http://subcube.com
https://github.com/t-o-k Post a reply to this message
 |  |