|
|
|
|
|
|
| |
| |
|
|
|
|
| |
| |
|
|
As an educational exercise for myself I've created a set of macros to
handle quaternions, which can be useful for rotations. I've compiled
these macros into an include file which I've attached.
Povray thankfully includes the built-in "vaxis_rotate()" function. That,
along with a number of great macros in "transforms.inc", allows you to
handle pretty well all of your "rotational" requirements. So why would
you want to use quaternions to do rotations in Povray? Primarily for
incremental and true angular interpolation rotations. And I've found a
few other uses myself, you might as well.
Quaternions are 4D vectors. Yes, they use complex numbers and are
difficult to understand, but you don't need to preoccupy yourself with
any of this to take advantage of them for 3D rotations. You can think of
a unit (normalized) quaternion as a representation of a rotation. So one
single 4D vector can represent any rotation around any axis. When you
multiply two unit quaternions together, you are effectively adding two
rotations together. Other quaternion tricks are used in these macros
which you may find useful.
If anyone else finds this useful, let me know.
Post a reply to this message
Attachments:
Download 'quaternions.inc.txt' (6 KB)
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Could you post a working demo scene?
thanks very much.
D.
"None" <Non### [at] onca> wrote in message
news:Xns### [at] 204213191226...
> As an educational exercise for myself I've created a set of macros to
> handle quaternions, which can be useful for rotations. I've compiled
> these macros into an include file which I've attached.
>
> Povray thankfully includes the built-in "vaxis_rotate()" function. That,
> along with a number of great macros in "transforms.inc", allows you to
> handle pretty well all of your "rotational" requirements. So why would
> you want to use quaternions to do rotations in Povray? Primarily for
> incremental and true angular interpolation rotations. And I've found a
> few other uses myself, you might as well.
>
> Quaternions are 4D vectors. Yes, they use complex numbers and are
> difficult to understand, but you don't need to preoccupy yourself with
> any of this to take advantage of them for 3D rotations. You can think of
> a unit (normalized) quaternion as a representation of a rotation. So one
> single 4D vector can represent any rotation around any axis. When you
> multiply two unit quaternions together, you are effectively adding two
> rotations together. Other quaternion tricks are used in these macros
> which you may find useful.
>
> If anyone else finds this useful, let me know.
>
>
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Entre otras cosas, None tuvo a bien escribir:
> As an educational exercise for myself I've created a set of macros to
> handle quaternions, which can be useful for rotations. I've compiled
> these macros into an include file which I've attached.
>
> [...]
>
> If anyone else finds this useful, let me know.
Interesting... I've seen quaternions in a molecular dynamics program called
MOLDY (it simulates rigid molecules, and uses quaternions to control their
rotations).
As has already been requested, any example of use?
--
light_source{9+9*x,1}camera{orthographic look_at(1-y)/4angle 30location
9/4-z*4}light_source{-9*z,1}union{box{.9-z.1+x clipped_by{plane{2+y-4*x
0}}}box{z-y-.1.1+z}box{-.1.1+x}box{.1z-.1}pigment{rgb<.8.2,1>}}//Jellby
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
"Dennis Miller" <dhm### [at] comcastnet> wrote in news:3f81d703$1
@news.povray.org:
> Could you post a working demo scene?
ok.
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Jellby <jel### [at] M-yahoocom> wrote in news:3f81dba5@news.povray.org:
> [...]
> As has already been requested, any example of use?
I'll post one in this thread.
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
As requested, find attached a sample file demonstrating basic use of
quaternions.inc for rotations. It's very simple (has more comments than
SDL), but I thought that was the best thing to get someone started.
Cheers.
Post a reply to this message
Attachments:
Download 'QSample1.pov.txt' (3 KB)
|
|
| |
| |
|
|
|
|
| |
| |
|
|
None <Non### [at] onca> wrote in news:Xns### [at] 204213191226:
> As requested, find attached a sample file demonstrating basic use of
> quaternions.inc for rotations. It's very simple (has more comments than
> SDL), but I thought that was the best thing to get someone started.
Alain, your quaternions.inc file has some problems: Just look at all
the "Divide by zero" warnings generated when parsing your sample file.
I can help you with some of them if you are intereseted.
Tor Olav
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Tor Olav Kristensen <tor_olav_kCURLYAhotmail.com> wrote in
news:Xns### [at] 204213191226:
> Alain, your quaternions.inc file has some problems: Just look at all
> the "Divide by zero" warnings generated when parsing your sample file.
>
> I can help you with some of them if you are intereseted.
>
>
> Tor Olav
Yes, the divide by zero messages are coming from the Qln() & QExp() macros
where I have attempted to trap them with a conditional, but they still
occur, it's strange. But I think the end result is the same.
If you are interested in helping it would be greatly appreciated.
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
None <Non### [at] onca> wrote in news:Xns### [at] 204213191226:
> Tor Olav Kristensen <tor_olav_kCURLYAhotmail.com> wrote in
> news:Xns### [at] 204213191226:
>
>> Alain, your quaternions.inc file has some problems: Just look at all
>> the "Divide by zero" warnings generated when parsing your sample
>> file.
>>
>> I can help you with some of them if you are intereseted.
>>
>>
>> Tor Olav
>
> Yes, the divide by zero messages are coming from the Qln() & QExp()
> macros where I have attempted to trap them with a conditional, but
> they still occur, it's strange. But I think the end result is the
> same.
>
> If you are interested in helping it would be greatly appreciated.
>
Note that in this expression:
(C ? A : B)
- both A and B are evaluated.
(I find this odd. IIRC this has been discussed somewhere in
these groups before. But I cannot remember if any good reasons
for this behaviour have been given.)
So your attempt to trap any division by zero errors by using
this conditional expression does not work smoothly.
It is my opinion that section '6.1.3.3 Float Operators' in the
manual should mention this behaviour.
My suggestion is to use #if #then and #else instead in such
cases.
But even if you do this in your Qln() and QExp() macros, there
is still one divide by zero warning left. It is triggered by
the QAxAn() macro. The 4th component (t) of a quaternion passed
to the macro is set to 1. - And this causes this expression to
be evaulated to zero: sqrt(1-Q.t*Q.t)
(It seems to me that it is the QBezier() macro that sets this
4th component to 1.)
Note that it is not advisable for users to use variable names
that are all lovercase letters (especially not for single
letter names).
(This is because these may be used for reserved keywords in
later versions of POV-Ray.)
See code below for my suggestions.
P.S.: POV-Ray has an epsilon constant (= 1.0E-10) that it uses
in float comparisons. So it might not be necessary to use one
yourself, like you do when checking if the R variable is close
to zero.
Btw.: Are you sure that log() and not ln() should be used in
the QExp() macro ?
Tor Olav
#include "functions.inc" // For f_r()
#macro Qln(Q)
#local R = f_r(Q.x, Q.y, Q.z);
#if (R > 0)
#local At = atan2(R, Q.t)/R;
#else
#local At = 0;
#end // if
<At*Q.x, At*Q.y, At*Q.z, 0.5*log(Qsc(Q))>
#end // macro Qln
#macro QExp(Q)
#local R = f_r(Q.x, Q.y, Q.z);
#local Et = exp(Q.t);
#if (R > 0)
#local S = sin(R)/R;
#else
#local S = 0;
#end // if
(Et*<S*Q.x, S*Q.y, S*Q.z, cos(R)>)
#end // macro QExp
#macro QAxAn(Q, An)
#declare An = acos(Q.t)*2;
(<Q.x, Q.y, Q.z>/sqrt(1-Q.t*Q.t))
#end // macro QAxAn
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Tor Olav Kristensen <tor_olav_kCURLYAhotmail.com> wrote in
news:Xns### [at] 204213191226:
...
> Btw.: Are you sure that log() and not ln() should be used in
> the QExp() macro ?
...
Sorry. I meant the Qln() macro.
Tor Olav
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |