POV-Ray : Newsgroups : povray.newusers : rounding and logic functions Server Time
22 Dec 2024 06:55:33 EST (-0500)
  rounding and logic functions (Message 1 to 10 of 16)  
Goto Latest 10 Messages Next 6 Messages >>>
From: Bald Eagle
Subject: rounding and logic functions
Date: 2 Aug 2013 00:55:04
Message: <web.51fb3b6e744b4afe73fc9ebb0@news.povray.org>
I was plotting some data, (Version 3.6) and I had a lot of trouble getting
otherwise programmatically simple goals accomplished.

I see there are ceil() and floor() directives, though these seem suspect.

There's div(A,B)

There's mod(), the definition of which in the manual seems ... odd.
a remainder ought to be (A/B) - int(A/B)
But the manual says that this is them multiplied by B
Maybe I'm just ignorant abut the definition of "modulus", but then the textual
definition in the manual is misleading.

There's int()

Is there no simple ROUND() function?  To round a number to Q decimal places?


Also, how do I perform an OR comparison?

IF (X = A _OR_ B)?


Thanks again to those more knowledgeable than I.


Post a reply to this message

From: clipka
Subject: Re: rounding and logic functions
Date: 2 Aug 2013 01:52:36
Message: <51fb4924$1@news.povray.org>
Am 02.08.2013 06:54, schrieb Bald Eagle:
>
> I was plotting some data, (Version 3.6) and I had a lot of trouble getting
> otherwise programmatically simple goals accomplished.
>
> I see there are ceil() and floor() directives, though these seem suspect.

What's wrong with them?


> There's mod(), the definition of which in the manual seems ... odd.
> a remainder ought to be (A/B) - int(A/B)

That would be the fractional part of a division result, not the remainder.

Suppose you have ten pieces of cake, you have to split them fairly among 
three children, and cutting a piece into smaller ones is not an option. 
What's the result? Of course each child gets three pieces of cake, with 
one piece of cake /remaining/. Hence, an integer division of 10/3 yields 
3, and a /remainder/ of 1.

> But the manual says that this is them multiplied by B
> Maybe I'm just ignorant abut the definition of "modulus", but then the textual
> definition in the manual is misleading.

What's misleading about that? The formula given is unambiguous, the 
statement that mod(A,B) gives the value of A modulo B is straightforward 
(and true), and the statement that it returns the remainder after the 
integer division of A/B is also simple and true.


> Is there no simple ROUND() function?  To round a number to Q decimal places?

You can achieve a round-to-nearest-integer using ceil(X-0.5); You can 
achieve a round-to-Q-decimal-places by multiplying before and dividing 
after, such as in:

     ceil( X*pow(10,Q) - 0.5 ) * pow(0.1,Q)


> Also, how do I perform an OR comparison?
>
> IF (X = A _OR_ B)?

simple - just perform two individual comparisons and apply the OR 
operator ("|"):

#if ((x = a) | (x = b))


Post a reply to this message

From: clipka
Subject: Re: rounding and logic functions
Date: 2 Aug 2013 02:01:40
Message: <51fb4b44$1@news.povray.org>
Am 02.08.2013 07:52, schrieb clipka:

> the
> statement that mod(A,B) gives the value of A modulo B is straightforward
> (and true)

(...though strictly speaking it should state that mod(A,B) gives the 
smallest value that is "equivalent modulo B" to A, but nobody in the 
world of computer programming would express it this way)


Post a reply to this message

From: Bald Eagle
Subject: Re: rounding and logic functions
Date: 3 Aug 2013 11:10:01
Message: <web.51fd1cfc87475f8873fc9ebb0@news.povray.org>
I was doing a simple #if - #else - #end loop and trying to trigger an update
once every "hour".
#if ( Time1 = ceil ( Time1 ) )

> What's wrong with them?

They just seemed to operate opposite to how I expected, but it could just be
that I was tired and the problem was my brain, not the functions.  I'm going to
investigate further.  With coffee.  :)


Your cake analogy cleared that up immensely.  I now can "see" the process
clearly in my mind.  Thanks!

> > Is there no simple ROUND() function?  To round a number to Q decimal places?
>
> You can achieve a round-to-nearest-integer using ceil(X-0.5); You can
> achieve a round-to-Q-decimal-places by multiplying before and dividing
> after, such as in:
>
>      ceil( X*pow(10,Q) - 0.5 ) * pow(0.1,Q)

Right.  I guess I wanted truly simple and straightforward, not the "you can
write your own formula for doing what should only t5ake invoking an easily
remembered and commonly used command".
It's also rather frustrating to a noob when searching for "round", and there's
no cross-index for floor and ceil, terms which no one would ever think to search
for.


> simple - just perform two individual comparisons and apply the OR
> operator ("|"):
>
> #if ((x = a) | (x = b))

Oh.  Bald Eagle, meet the OR operator.  OR operator, Bald Eagle.  I'll let you
two get acquainted.

That would have been a helpful cross index as well.
I searched for OR, Boolean, comparators, if, logic, functions, ....   no OR.


Post a reply to this message

From: clipka
Subject: Re: rounding and logic functions
Date: 3 Aug 2013 17:20:16
Message: <51fd7410$1@news.povray.org>
Am 03.08.2013 17:08, schrieb Bald Eagle:

>> You can achieve a round-to-nearest-integer using ceil(X-0.5); You can
>> achieve a round-to-Q-decimal-places by multiplying before and dividing
>> after, such as in:
>>
>>       ceil( X*pow(10,Q) - 0.5 ) * pow(0.1,Q)
>
> Right.  I guess I wanted truly simple and straightforward, not the "you can
> write your own formula for doing what should only t5ake invoking an easily
> remembered and commonly used command".
> It's also rather frustrating to a noob when searching for "round", and there's
> no cross-index for floor and ceil, terms which no one would ever think to search
> for.

Well, that would be too easy, wouldn't it :-P

Frankly, I'm not the best person to discuss documentation matters; I'm 
happy when I can dump my description of new features into someone else's 
lap, and let them sort out where it fits best, where it should be 
cross-linked, and all that sort of stuff. James Holsenback has been 
doing great work in that respect, and he also has been giving the 
documentation a general facelift; I guess he'll be happy about hints 
like yours pointing out potential for even further improvement. After 
all there's one thing that becomes more and more difficult the more one 
gets acquainted to a piece of software and its documentation: To notice 
potential problems that new users might run into.


Post a reply to this message

From: Bald Eagle
Subject: Re: rounding and logic functions
Date: 3 Aug 2013 17:55:01
Message: <web.51fd7bae87475f8873fc9ebb0@news.povray.org>
> Well, that would be too easy, wouldn't it :-P

Right-o.  What's life without a challenge, eh?

> I guess he'll be happy about hints
> like yours pointing out potential for even further improvement. After
> all there's one thing that becomes more and more difficult the more one
> gets acquainted to a piece of software and its documentation: To notice
> potential problems that new users might run into.

Indeed.  You acheive a certain myopia and over-familiarity.  That's why you have
OTHER people proofread your work, because you tend read right THROUGH the
errors.

I'm trying to illustrate to myself how things work, so maybe some of those ideas
will help out with clarifying the docs.


Post a reply to this message

From: Alain
Subject: Re: rounding and logic functions
Date: 3 Aug 2013 18:35:39
Message: <51fd85bb$1@news.povray.org>

>
> I was doing a simple #if - #else - #end loop and trying to trigger an update
> once every "hour".
> #if ( Time1 = ceil ( Time1 ) )
>

Using such a loop would only work for a *very* long parse operation as 
it can only be evaluated during that time. When rendering or editing 
your scene, the loop is never used.


Alain


Post a reply to this message

From: James Holsenback
Subject: Re: rounding and logic functions
Date: 3 Aug 2013 18:56:15
Message: <51fd8a8f$1@news.povray.org>
On 08/03/2013 05:52 PM, Bald Eagle wrote:
>
>> Well, that would be too easy, wouldn't it :-P
>
> Right-o.  What's life without a challenge, eh?
>
>> I guess he'll be happy about hints
>> like yours pointing out potential for even further improvement. After
>> all there's one thing that becomes more and more difficult the more one
>> gets acquainted to a piece of software and its documentation: To notice
>> potential problems that new users might run into.
>
> Indeed.  You acheive a certain myopia and over-familiarity.  That's why you have
> OTHER people proofread your work, because you tend read right THROUGH the
> errors.
>
> I'm trying to illustrate to myself how things work, so maybe some of those ideas
> will help out with clarifying the docs.
>
>

What did you have in mind ... I could add an index entry to ceil and 
floor so they come up when round is the search term. That would be on 
windows version only. Mileage may vary. As far as expanding the 
reference section 
http://wiki.povray.org/content/Reference:Numeric_Expressions#Functions 
(where ceil and floor are mentioned) I don't see a lot of room there 
given the format used for the rest of the functions. Maybe a small 
example /could/ be made to fit into the current scheme, but that 
/really/ doesn't do anything to address the fact you weren't aware that 
ceil and floor could be used like clipka showed ... at the moment kings 
x on coming up with a different layout. For the heck of it I took a 
quick tour of the tutorial and see that it's lacking in any sort of 
information about writing functions, so I guess I'm out of ideas


Post a reply to this message

From: Bald Eagle
Subject: Re: rounding and logic functions
Date: 3 Aug 2013 21:45:01
Message: <web.51fdb16487475f8873fc9ebb0@news.povray.org>
Well, to start off, I find that things like this help me to understand things
WAY more than text.
http://news.povray.org/povray.binaries.tutorials/thread/%3Cweb.51f61e827603294573fc9ebb0%40news.povray.org%3E/
A picture's worth a thousand words, and all that.

Here's what my first impressions are when I look at that wiki page:

That green text is WAY too small.
I don't know what a unary minus or a unary plus is.
I'd expect mention of exponential functions in the precedence listing.
I'd also point out that (A^2) is not a valid expression - pow(x,2) is the way to
write that in POV-Ray.  And don't confuse pow() with pwr().
I think I tried doing an #if (X=<Y), but the <has to precede the =
I don't know what a bit-wise operation is
THEN should be searchable and linked to the ? operator

abs(A)
Absolute value of A. If A is negative, returns -A otherwise returns A.
#debug concat ("ABS -1 = ",str(abs(-1),3,0)) returns 1, not -1.

I don't know what hyperbolic trig functions are (off the top of my head)

#declare Step = 0;
#while (Step <= 2)
#debug concat ("Number = ",str(Step,3,1))
#debug "\n"
#debug concat ("ceiling = ",str(ceil(Step),3,1))
#debug "\n"
#debug concat ("floor = ",str(ceil(Step),3,1))
#debug "\n"
#debug "\n"
#declare Step = Step + 0.1;
#end

Floor and ceiling return the same value.
THAT's what's wrong with them.

For the function inside(), what is the "object identifier"? is that something
like #declare O=object{}?

strlen() is useful for text functions, but for rendering text in an image, I'd
like to know how large that text will actually be.

You have tan(A) and tanh(), but tan2(A,B) is ... elsewhere.

will val(s) accept val("3X")?

I HAD to render and animate the dot product file in order to understand what it
did.  The text didn't help me understand that it was a vector perpendicular to
the two vectors I was ... dotting.

.... and as a noob, I find it a little disorienting when an example uses some
obscure POV-Ray function without a prior simple/common one...
#if (image_width < 300) crand 0.1 #else crand 0.5 #end
.... because now I have to interrupt my train of thought and go off on some
tangent to look up what "crand" is.

So, there's an example of my constructive criticism.

Feel free to email me with requests for illustrations or proofreading /
commentary.

Thanks for what I'm sure is a TON of hard work, James.  I've been there, so I
know what it's like.


Post a reply to this message

From: Bald Eagle
Subject: Re: rounding and logic functions
Date: 3 Aug 2013 21:55:01
Message: <web.51fdb3a287475f8873fc9ebb0@news.povray.org>
Alain <kua### [at] videotronca> wrote:

> >
> > I was doing a simple #if - #else - #end loop and trying to trigger an update
> > once every "hour".
> > #if ( Time1 = ceil ( Time1 ) )
> >
>
> Using such a loop would only work for a *very* long parse operation as
> it can only be evaluated during that time. When rendering or editing
> your scene, the loop is never used.
>
>
> Alain

Well, the parse and render phases are something I need to better understand,
because I long to do cool stuff with functions and macros, and I've seen that
asked plenty of times.  Lots of reading and experiments for me.

I used the loop in my render, and it seemed to work fine.

  #if ( Time1 = ceil ( Time1 ) )
   #declare A = A + B;
   #declare B = B + 2;
   text { ttf "arial.ttf" str (B, 3, 0) 0.1, 0 translate <Time1-2,
Level1*Y_Factor+2, -0.4> pigment {color Yellow}}
   #debug concat ("Time1 = ", str (Time1, 3, 1))
   #debug "\n"
   #debug concat ("A = ", str (A, 3, 1))
   #debug "\n"
  #else
  #end // end if

once I got the #if comparator right, it worked just like I expected it to.

#if ( Time1 / Step = int (Time1/Step)  DID NOT work.
Go figure.


Post a reply to this message

Goto Latest 10 Messages Next 6 Messages >>>

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