POV-Ray : Newsgroups : povray.advanced-users : Condition in functions Server Time
21 Dec 2024 12:11:43 EST (-0500)
  Condition in functions (Message 1 to 10 of 18)  
Goto Latest 10 Messages Next 8 Messages >>>
From: kurtz le pirate
Subject: Condition in functions
Date: 6 Dec 2024 06:15:08
Message: <6752dcbc@news.povray.org>
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.
I'm trying to figure out why the “laces” are missing.





Thanks



-- 
kurtz le pirate
compagnie de la banquise


Post a reply to this message


Attachments:
Download 'vase.png' (102 KB)

Preview of image 'vase.png'
vase.png


 

From: Bald Eagle
Subject: Re: Condition in functions
Date: 6 Dec 2024 07:05:00
Message: <web.6752e771320682331f9dae3025979125@news.povray.org>
kurtz le pirate <kur### [at] freefr> wrote:

> This exemple come from MathMod, "Vase_3 by Abderrahman Taha 31/10/2019"

Nice.  There have been a lot of MathMod shapes that I'd like to replicate in
POV-Ray.

> Do you agree with the use of select() to replace if() ?
Yes - there are few other options to do that, if any.

> On the left is MathMod, on the right where I am.


No time for me to investigate this in detail right now but:

Isosurfaces of complex things can be tricky - especially if you're trying to use
certain "forms" of equations.

First thing is to check messages and see what the gradient is.

Then I'd try to take the abs () of the equation and subtract a tiny amount to
see if anything shows up.

Then I might see if subtracting the equation from the r (x,y,z) function gets
you anywhere.

- BW


Post a reply to this message

From: Alain Martel
Subject: Re: Condition in functions
Date: 6 Dec 2024 08:38:22
Message: <6752fe4e$1@news.povray.org>
Le 2024-12-06 à 06:15, kurtz le pirate a écrit :
> 
> 
> 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.

As if() can't be used in the function of an isosurface, select() is 
pretty much the only option.

> 
> 
> 
> On the left is MathMod, on the right where I am.
> I'm trying to figure out why the “laces” are missing.
> 
> 
> 
> 
> 
> Thanks
> 
> 
>


Post a reply to this message

From: Bald Eagle
Subject: Re: Condition in functions
Date: 6 Dec 2024 13:45:00
Message: <web.6753460f32068233b00a87a025979125@news.povray.org>
Alain Martel <kua### [at] videotronca> wrote:

> As if() can't be used in the function of an isosurface, select() is
> pretty much the only option.

Well, I don't think that's entirely true.

If you take advantage of the fact that expressions inside of parentheses get
evaluated, and make use of functions like sgn, min, max, etc, then you can
multiply terms in an equation by values that select them (multiply by 1 or -1)
or cancel them out (multiply by 0).

So if you wanted to alternate signs, you could use a sine wave and take the sign
of that:  sgn(sin(N))

- BW


Post a reply to this message

From: Alain Martel
Subject: Re: Condition in functions
Date: 6 Dec 2024 14:34:59
Message: <675351e3$1@news.povray.org>
Le 2024-12-06 à 13:44, Bald Eagle a écrit :
> Alain Martel <kua### [at] videotronca> wrote:
> 
>> As if() can't be used in the function of an isosurface, select() is
>> pretty much the only option.
> 
> Well, I don't think that's entirely true.
> 
> If you take advantage of the fact that expressions inside of parentheses get
> evaluated, and make use of functions like sgn, min, max, etc, then you can
> multiply terms in an equation by values that select them (multiply by 1 or -1)
> or cancel them out (multiply by 0).
> 
> So if you wanted to alternate signs, you could use a sine wave and take the sign
> of that:  sgn(sin(N))
> 
> - BW
> 

According to what I remember from a discussion here a while back :
The if() is normally evaluated at parse time. That makes it unsuitable 
to be used in an isosurface that need to evaluate it at render time.


Post a reply to this message

From: Bald Eagle
Subject: Re: Condition in functions
Date: 6 Dec 2024 15:25:00
Message: <web.67535ccd32068233b00a87a025979125@news.povray.org>
Alain Martel <kua### [at] videotronca> wrote:

> select() is
> >> pretty much the only option.

> > Well, I don't think that's entirely true.

What I meant is that select() is not the ONLY option.

It will be a while before I can check and confirm, but I think that one can
embed conditional statements into a function such as (Theta < pi/2) which will
be evaluated to true (1) or false (0).

Plus all of the other methods I referred to.

- BW


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: Condition in functions
Date: 7 Dec 2024 13:55:00
Message: <web.67549961320682334afe95ff89db30a9@news.povray.org>
kurtz le pirate <kur### [at] freefr> 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

From: kurtz le pirate
Subject: Re: Condition in functions
Date: 8 Dec 2024 11:25:16
Message: <6755c86c$1@news.povray.org>
On 07/12/2024 19:54, Tor Olav Kristensen wrote:

> Hi Kurtz
> 
> That's an interesting project.
> 
> I found some MathMod documentation here:
>
https://fossies.org/linux/mathmod/documentation/index.html#SupportedOperatorsFunctions

Hi Tor,

I also found the doc in the MathMod package.


> 
> ...
> ...
> ...
> 
> 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.)
> 
Yes, indeed, difficult to understand.
MathMod's language is, on certain points, obscure ... at least for me.

I also have problems with PrettyBall_1. 3 isosurfaces. Two are ok. The 
third really doesn't match. Yet the code is/looks ok.



> 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.
> 

Ingenious approach. I'm going to look into it very closely.




Thanks+



-- 
kurtz le pirate
compagnie de la banquise


Post a reply to this message

From: kurtz le pirate
Subject: Re: Condition in functions
Date: 9 Dec 2024 10:52:49
Message: <67571251$1@news.povray.org>
Following Tor's advice, I corrected my 'select()'.

I've also put the 't' parameter back into the functions. I mistakenly 
thought that this parameter was only used for animation and morphing. 
This is not the case at all.


I put an image of the result in p.b.i.


I can ost functions if someone is interested.



-- 
kurtz le pirate
compagnie de la banquise


Post a reply to this message

From: jr
Subject: Re: Condition in functions
Date: 9 Dec 2024 23:55:00
Message: <web.6757c8a332068233b2e841a6cde94f1@news.povray.org>
hi,

kurtz le pirate <kur### [at] freefr> wrote:
> ...
> I put an image of the result in p.b.i.
> I can ost functions if someone is interested.

the vase looks pretty cool.  the functions as such would not be much use to me,
I guess, but how about creating a macro ?  perhaps with options to supply one's
own material and for scaling (making the vase taller/shorter, slimmer/more
bulge), and such ?


regards, jr.


Post a reply to this message

Goto Latest 10 Messages Next 8 Messages >>>

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