POV-Ray : Newsgroups : povray.binaries.images : Rotation matrices Server Time
25 Apr 2024 14:15:13 EDT (-0400)
  Rotation matrices (Message 6 to 15 of 15)  
<<< Previous 5 Messages Goto Initial 10 Messages
From: Thomas de Groot
Subject: Re: Rotation matrices
Date: 5 Apr 2021 11:38:28
Message: <606b2ef4$1@news.povray.org>
Op 5-4-2021 om 13:08 schreef Bald Eagle:
> Thomas de Groot <tho### [at] degrootorg> wrote:
> 
>> or use stochastic aa. That would solve the problem in an elegant way.
> 
> You've gotta school me in that black art.   Although I have delved deeply into
> some of the more esoteric areas of POV-Ray, through neglect, I still have the
> lowest level of understanding with regard to the antialiasing settings.
> 
> is that the +ua or the +am3, or another one... ?
> 
> 

I currently use:

// +am3 +a0.01 +ac0.90 +r3

Which gives me good results. Higher settings, but slower, would be:

// +am3 +a0.001 +ac0.99 +r4

And faster, but uglier, good for testing, something like:

// +am3 +a0.1 +ac0.80 +r2

-- 
Thomas


Post a reply to this message

From: Bald Eagle
Subject: Re: Rotation matrices
Date: 5 Apr 2021 16:55:00
Message: <web.606b78af565eea121f9dae3025979125@news.povray.org>
Thomas de Groot <tho### [at] degrootorg> wrote:

> // +am3 +a0.001 +ac0.99 +r4

I tried that, but even that wasn't good enough to make the "=" fully visible.

scaling along y by 1.2 improved matters, but then I just switched over to Times
New Roman Bold and kept the scaling as well.
Changed the angles to radians.
Slight color changes on the tori.

I didn't feel like going full utf8 to get a proper pi character - yet.


Post a reply to this message


Attachments:
Download 'rotationmatrices.png' (416 KB)

Preview of image 'rotationmatrices.png'
rotationmatrices.png


 

From: Thomas de Groot
Subject: Re: Rotation matrices
Date: 6 Apr 2021 02:07:27
Message: <606bfa9f@news.povray.org>
Op 05/04/2021 om 22:53 schreef Bald Eagle:
> Thomas de Groot <tho### [at] degrootorg> wrote:
> 
>> // +am3 +a0.001 +ac0.99 +r4
> 
> I tried that, but even that wasn't good enough to make the "=" fully visible.
> 
> scaling along y by 1.2 improved matters, but then I just switched over to Times
> New Roman Bold and kept the scaling as well.
> Changed the angles to radians.
> Slight color changes on the tori.
> 
> I didn't feel like going full utf8 to get a proper pi character - yet.
> 

It is the results that count. :-)

-- 
Thomas


Post a reply to this message

From: Kenneth
Subject: Re: Rotation matrices
Date: 6 Apr 2021 13:10:00
Message: <web.606c948f565eea12d98418916e066e29@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:
> "Tor Olav Kristensen" <tor### [at] TOBEREMOVEDgmailcom> wrote:
>
> > I also suggest that you insert a note to the reader that POV-Ray's
> > trigonometric functions use radians, not degrees as in you[r] basis
> > vector lists.
>
> I will keep that in mind.  I have one or two other "documentation illustrations"
> in mind.

I usually like to use trig functions in degrees rather than radians-- just
easier to visualize for me. "math.inc" has some simple little 'converter'
functions, sind() and cosd()

So in your diagram, for example...
T5: y'= <0,cosd(180), sind(180>

But for your matrix illustrations, I don't know if they should be used (since I
don't know enough about matrix math).
    like,  -sind  instead of  -sin  ??


Post a reply to this message

From: Bald Eagle
Subject: Re: Rotation matrices
Date: 6 Apr 2021 17:20:00
Message: <web.606cd03d565eea121f9dae3025979125@news.povray.org>
"Kenneth" <kdw### [at] gmailcom> wrote:

> I usually like to use trig functions in degrees rather than radians-- just
> easier to visualize for me. "math.inc" has some simple little 'converter'
> functions, sind() and cosd()

I was playing around with some things the other day, writing my function
document,  and noticed that we don't need "math.inc" anymore - at least not in
3.8.   :)

> But for your matrix illustrations, I don't know if they should be used (since I
> don't know enough about matrix math).

I just put sin and cos because everyone everywhere knows what that is and I
would hope that most people would assume that it's implied that there's a
degrees - to - radians conversion...   But "matrix math" is no different than
"spreadsheet math" or pencil and paper math or chalkboard math....   it's just a
way of laying things out so that the values in the places are operated on by the
appropriate values in the places of other matrices.  Or that the formulas for
things like determinants are using the right values.   No magic.

It's just an organizational thing to make the notation compact.

Just think about it as: array {Vec.x, Vec.y, Vec.z} and then make a 2D array
with 2 or 3 more vectors....


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: Rotation matrices
Date: 7 Apr 2021 00:50:00
Message: <web.606d38e0565eea128e52cc8789db30a9@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:
> "Tor Olav Kristensen" <tor### [at] TOBEREMOVEDgmailcom> wrote:
> ...  I would also like to figure out if there's a nice
> degrees-to-fractions-of-pi algorithm out there, and I could implement that.
> I'll probably just hard-code an array of text objects.

You can divide the angle by 180 and convert the resulting decimal number to a
fraction. Then you can use David Eppstein's "find rational approximation to
given real number" code as suggested in the first answer here:

https://stackoverflow.com/questions/95727/how-to-convert-floats-to-human-readable-fractions


>...
> Do you watch 3blue1brown's channel?   It's - peaceful, and elegant, and
> mesmerizing.  It's one of the best things to happen to math in a long while.
> :)

Yes, I've seen some of his videos. Very good =)
I'm looking forward to the rest of them.

--
Tor Olav
http://subcube.com
https://github.com/t-o-k


Post a reply to this message

From: Bald Eagle
Subject: Re: Rotation matrices
Date: 2 Mar 2023 07:20:00
Message: <web.6400937d565eea121f9dae3025979125@news.povray.org>
"Tor Olav Kristensen" <tor### [at] TOBEREMOVEDgmailcom> wrote:
> "Bald Eagle" <cre### [at] netscapenet> wrote:
> > "Tor Olav Kristensen" <tor### [at] TOBEREMOVEDgmailcom> wrote:
> > ...  I would also like to figure out if there's a nice
> > degrees-to-fractions-of-pi algorithm out there, and I could implement that.
> > I'll probably just hard-code an array of text objects.
>
> You can divide the angle by 180 and convert the resulting decimal number to a
> fraction. Then you can use David Eppstein's "find rational approximation to
> given real number" code as suggested in the first answer here:
>
>
https://stackoverflow.com/questions/95727/how-to-convert-floats-to-human-readable-fractions


I tried at least 2 different ways to go about this, but I didn't have any
success and fell into some kind of trap in the recursion programming that
short-circuits things.   It was a mess that I spent too many hours trying to
fix.

I have more application cases that I'd like to apply this sort of thing to, if
you give me a nudge in the proper direction.

Thanks,

- BW


Post a reply to this message


Attachments:
Download 'rationalapproximation.pov.txt' (7 KB)

From: Tor Olav Kristensen
Subject: Re: Rotation matrices
Date: 2 Mar 2023 13:35:00
Message: <web.6400ebee565eea12e9c9e5da89db30a9@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:
> "Tor Olav Kristensen" <tor### [at] TOBEREMOVEDgmailcom> wrote:
> > "Bald Eagle" <cre### [at] netscapenet> wrote:
> > > "Tor Olav Kristensen" <tor### [at] TOBEREMOVEDgmailcom> wrote:
> > > ...  I would also like to figure out if there's a nice
> > > degrees-to-fractions-of-pi algorithm out there, and I could implement that.
> > > I'll probably just hard-code an array of text objects.
> >
> > You can divide the angle by 180 and convert the resulting decimal number to a
> > fraction. Then you can use David Eppstein's "find rational approximation to
> > given real number" code as suggested in the first answer here:
> >
> >
https://stackoverflow.com/questions/95727/how-to-convert-floats-to-human-readable-fractions
>
>
> I tried at least 2 different ways to go about this, but I didn't have any
> success and fell into some kind of trap in the recursion programming that
> short-circuits things.   It was a mess that I spent too many hours trying to
> fix.
>
> I have more application cases that I'd like to apply this sort of thing to, if
> you give me a nudge in the proper direction.

Hi

As I know that you are very fond of Python, I'll nudge you to have a
look this code (which SEEMS to work ok):


# real_num: real number to approximate
# max_denom: maximum denominator allowed

def real_to_fraction(real_num, max_denom):

    max_int = 2**31 - 1  # LONG_MAX == 0x7FFFFFFF in C
    x = real_num
    max_denom = int(max_denom)
    m00 = int(1)
    m01 = int(0)
    m10 = int(0)
    m11 = int(1)

    # loop finding terms until denominator gets too big
    ai = int(x)
    while (m10*ai + m11 <= max_denom):
        tmp = m00*ai + m01
        m01 = int(m00)
        m00 = int(tmp)
        tmp = m10*ai + m11
        m11 = int(m10)
        m10 = int(tmp)
        if (x == ai):
            break  # AF: division by zero
        x = 1/(x - ai)
        if (abs(x) > max_int):
            break  # AF: representation failure
        ai = int(x)

    # now remaining x is between 0 and 1/ai
    # approximate as either 0 or 1/m where
    # m is max that will fit in max_denom

    # first try zero
    error = real_num - m00/m10
    print(f'{m00}/{m10}, error = {error}\n')

    # then try other possibility
    ai = int((max_denom - m11)/m10)
    m00 = int(m00*ai + m01)
    m10 = int(m10*ai + m11)
    error = real_num - m00/m10
    print(f'{m00}/{m10}, error = {error}\n')


Test run:

    real_to_fraction(3.875, 100)

    31/8, error = 0.0

    376/97, error = -0.0012886597938144284


The type long in C is the same as the type signed long int.
So I put  int() around every expression going into variables
of type long.

As you know, I don't like break statements in loops, so this
remains to be fixed.

In Python max_int should probably be chosen to be maxsize or
maxsize - 1 (after doing "from sys import maxsize").


--
Tor Olav
http://subcube.com
https://github.com/t-o-k


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: Rotation matrices
Date: 3 Mar 2023 09:45:00
Message: <web.6402079b565eea12d105cea189db30a9@news.povray.org>
"Tor Olav Kristensen" <tor### [at] TOBEREMOVEDgmailcom> wrote:
>...
>         tmp = m00*ai + m01
>         m01 = int(m00)
>         m00 = int(tmp)
>         tmp = m10*ai + m11
>         m11 = int(m10)
>         m10 = int(tmp)
>...

Sorry, that was not very Pythonic. I try again:

        m00, m01 = int(m00*ai + m01), int(m00)
        m10, m11 = int(m10*ai + m11), int(m10)

--
Tor Olav
http://subcube.com
https://github.com/t-o-k


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: Rotation matrices
Date: 3 Mar 2023 13:25:00
Message: <web.64023b43565eea12d105cea189db30a9@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:
> "Tor Olav Kristensen" <tor### [at] TOBEREMOVEDgmailcom> wrote:
> > "Bald Eagle" <cre### [at] netscapenet> wrote:
> > > "Tor Olav Kristensen" <tor### [at] TOBEREMOVEDgmailcom> wrote:
> > > ...  I would also like to figure out if there's a nice
> > > degrees-to-fractions-of-pi algorithm out there, and I could implement that.
> > > I'll probably just hard-code an array of text objects.
> >
> > You can divide the angle by 180 and convert the resulting decimal number to a
> > fraction. Then you can use David Eppstein's "find rational approximation to
> > given real number" code as suggested in the first answer here:
> >
> >
https://stackoverflow.com/questions/95727/how-to-convert-floats-to-human-readable-fractions
>
>
> I tried at least 2 different ways to go about this, but I didn't have any
> success and fell into some kind of trap in the recursion programming that
> short-circuits things.   It was a mess that I spent too many hours trying to
> fix.
>
> I have more application cases that I'd like to apply this sort of thing to, if
> you give me a nudge in the proper direction.

I just had a look at you code and found that perhaps you are
misunderstanding what the value of this C expression is:

(ai = (long)x)

This is an assignment, where the value in X is converted to an
unsigned long int, then converted to the type of ai (which is
also an unsigned long int) and then stored in ai. The value of
the whole parenthesis expression is now equal to ai and can be
used in further calculations.

See this page:
https://stackoverflow.com/questions/9514569/what-does-an-assignment-return

In POV-Ray's SDL this expression:

(ai = x)

- is a comparison that is true when ai equals x and false otherwise.
So the value of the parenthesis expression is either 0 (for false)
or 1 (for true).

See "Relational expressions" (and the text right before) here:
https://wiki.povray.org/content/Reference:Numeric_Expressions

Also, you should call your macros with the second argument
(for the d parameter) greater than or equal to the greatest
denominator that you will accept. I.e. If you will accept
denominators up to 100, then pass 100 (not something small as
0.000001).

--
Tor Olav
http://subcube.com
https://github.com/t-o-k


Post a reply to this message

<<< Previous 5 Messages Goto Initial 10 Messages

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