POV-Ray : Newsgroups : povray.advanced-users : Get Euler angles from unit vector? Server Time
16 Apr 2024 08:08:10 EDT (-0400)
  Get Euler angles from unit vector? (Message 4 to 13 of 13)  
<<< Previous 3 Messages Goto Initial 10 Messages
From: Mike Horvath
Subject: Re: Get Euler angles from unit vector?
Date: 22 Sep 2018 11:09:08
Message: <5ba65b14$1@news.povray.org>
On 9/22/2018 8:32 AM, clipka wrote:
> Am 22.09.2018 um 13:49 schrieb Mike Horvath:
>> Is it possible to extract the Euler rotation amounts from a unit vector?
>> Is there a command that does this? Thanks.
> 
> A unit vector by itself is not enough to fully specify a free rotation
> in 3D space; you need two vectors for that.
> 
> Most notably, a single unit vector representation would allow for
> arbitrary rotations around the direction of that vector.
> 


I found some old code written in Lua. Just need to adapt it to POV-Ray.

Mike



-- Returns an array containing the vector's Euler angles, relative to 
the Z-axis.
-- To reproduce the original vector, rotate a point on the Z-axis by 
these angles.
function vanglesXY(tVec2)
	local fSgnX, fSgnY, tPrjB1 = 1, 1, vnormalize({tVec2[1], 0, tVec2[3],})
	if (tPrjB1[1] ~= 0) then
		fSgnX = tPrjB1[1]/abs(tPrjB1[1]) * -1
	end
	tPrjB1[3] = max(min(tPrjB1[3],1),-1)
	local fAngY = acos(tPrjB1[3]) * fSgnX
	local tPrjB2 = vnormalize(vrotate(tVec2, {0, fAngY, 0,}))
	if (tPrjB2[2] ~= 0) then
		fSgnY = tPrjB2[2]/abs(tPrjB2[2])
	end
	tPrjB2[3] = max(min(tPrjB2[3],1),-1)
	local fAngX = acos(tPrjB2[3]) * fSgnY
	return {fAngX * -1, fAngY * -1, 0,}
end


Post a reply to this message

From: Kenneth
Subject: Re: Get Euler angles from unit vector?
Date: 22 Sep 2018 15:40:00
Message: <web.5ba69a61809fadada47873e10@news.povray.org>
Mike Horvath <mik### [at] gmailcom> wrote:
> Is it possible to extract the Euler rotation amounts from a unit vector?
> Is there a command that does this? Thanks.
>

Methinks you're working on a way to re-structure a transform{matrix...} back
into rotation angles ;-)

[possibly off-topic]
Reading the Wikipedia entry about 'Euler angles' (probably for the first time!),
particularly the 'simplified' form, it reminded me of some test animations I did
years ago, of an object rotating in free space. Like, a chunk of rock slowly
rotating way out in the cosmos.

At first, I thought the object needed THREE separate rotations to look right.
That seemed logical-- if only from the standpoint of an airplane's 'yaw, pitch
and roll.' But the result looked odd-- like there was an extra invisible force
acting on it (and/or that the object was ending up in the same orientation it
started in, very quickly.) Just from experimenting, I found that restricting the
rotations to TWO axes *looked* to be much more natural, and that the third-axis
rotation was... redundant-- which seems to agree with the notion of 'simplified'
Euler angles, where the needed rotations can actually be around two axes rather
than three, to get any orientation (if I'm reading the definition properly, that
is!)

Not that this is of any help to you :-(


Post a reply to this message

From: Mike Horvath
Subject: Re: Get Euler angles from unit vector?
Date: 27 Sep 2018 19:40:38
Message: <5bad6a76$1@news.povray.org>
It would be nice to be able to set vector components like this:

     #local tPrjB1.z = max(min(tPrjB1.z,1),-1);

Are there any plans to do this in the future?



Mike


Post a reply to this message

From: clipka
Subject: Re: Get Euler angles from unit vector?
Date: 27 Sep 2018 19:47:04
Message: <5bad6bf8$1@news.povray.org>
Am 28.09.2018 um 01:40 schrieb Mike Horvath:
> It would be nice to be able to set vector components like this:
> 
>     #local tPrjB1.z = max(min(tPrjB1.z,1),-1);
> 
> Are there any plans to do this in the future?

Thought about it, but it would mean creeping into the dirtiest corners
of the parser.

Not off the agenda, but not right around the corner either.


Post a reply to this message

From: Mike Horvath
Subject: Re: Get Euler angles from unit vector?
Date: 27 Sep 2018 20:32:57
Message: <5bad76b9$1@news.povray.org>
On 9/22/2018 3:39 PM, Kenneth wrote:
> Mike Horvath <mik### [at] gmailcom> wrote:
>> Is it possible to extract the Euler rotation amounts from a unit vector?
>> Is there a command that does this? Thanks.
>>
> 
> Methinks you're working on a way to re-structure a transform{matrix...} back
> into rotation angles ;-)
> 

Yes. Is there a somewhat simple method of doing this so that I don't 
have to write separate code for each possible matrix convention? (There 
are six possibilities, even when not taking into consideration that the 
handedness might also vary.)


Mike


Post a reply to this message

From: Mike Horvath
Subject: Re: Get Euler angles from unit vector?
Date: 27 Sep 2018 21:27:38
Message: <5bad838a$1@news.povray.org>
Two important questions I have (that may not be explained in the docs), 
is how to convert a 3x3 rotation matrix to POV-Ray syntax, and how to 
determine the inverse matrix?


Mike


Post a reply to this message

From: clipka
Subject: Re: Get Euler angles from unit vector?
Date: 28 Sep 2018 00:27:21
Message: <5badada9$1@news.povray.org>
Am 28.09.2018 um 03:27 schrieb Mike Horvath:
> Two important questions I have (that may not be explained in the docs),
> is how to convert a 3x3 rotation matrix to POV-Ray syntax, and how to
> determine the inverse matrix?

given a matrix

     / a  b  c \
    (  d  e  f  )
     \ g  h  i /

you have to specify either

    matrix < a, b, c,
             d, e, f,
             g, h, i,
             0, 0, 0 >

or
    matrix < a, d, g,
             b, e, h,
             c, f, i,
             0, 0, 0 >

The order depends on whether the original matrix is specified in
"mathematical" or "computer graphics" style - they're mirrored along the
diagonal. Can't remember which one POV-Ray uses.

Determining the inverse /transformation/ is simple:

    #declare Foo = transform { matrix < ... > }
    #declare FooInv = transform { Foo inverse }

Actually getting at the corresponding matrix is possible by applying the
inverted transformation to the axis vectors.


Post a reply to this message

From: Mike Horvath
Subject: Re: Get Euler angles from unit vector?
Date: 28 Sep 2018 00:36:03
Message: <5badafb3$1@news.povray.org>
Awesome, thanks!



On 9/28/2018 12:27 AM, clipka wrote:
> Am 28.09.2018 um 03:27 schrieb Mike Horvath:
>> Two important questions I have (that may not be explained in the docs),
>> is how to convert a 3x3 rotation matrix to POV-Ray syntax, and how to
>> determine the inverse matrix?
> 
> given a matrix
> 
>       / a  b  c \
>      (  d  e  f  )
>       \ g  h  i /
> 
> you have to specify either
> 
>      matrix < a, b, c,
>               d, e, f,
>               g, h, i,
>               0, 0, 0 >
> 
> or
>      matrix < a, d, g,
>               b, e, h,
>               c, f, i,
>               0, 0, 0 >
> 
> The order depends on whether the original matrix is specified in
> "mathematical" or "computer graphics" style - they're mirrored along the
> diagonal. Can't remember which one POV-Ray uses.
> 
> Determining the inverse /transformation/ is simple:
> 
>      #declare Foo = transform { matrix < ... > }
>      #declare FooInv = transform { Foo inverse }
> 
> Actually getting at the corresponding matrix is possible by applying the
> inverted transformation to the axis vectors.
>


Post a reply to this message

From: Le Forgeron
Subject: Re: Get Euler angles from unit vector?
Date: 28 Sep 2018 02:42:18
Message: <5badcd4a$1@news.povray.org>
Le 28/09/2018 à 03:27, Mike Horvath a écrit :
> Two important questions I have (that may not be explained in the docs), 
> is how to convert a 3x3 rotation matrix to POV-Ray syntax, and how to 
> determine the inverse matrix?
> 
> 
> Mike



you only have to input a 3x4 ( column x line), but the math beyond use a 
4x4 matrix with a fourth column set to
{ 0,
   0,
   0,
   1 }
(the 4x4 is important, when combining transformation, a 4x4 * 4x4 -> 
4x4, whereas it make no sense with 3x4 )

The fourth line is the translation

http://wiki.povray.org/content/Reference:Transformations#Matrix

To input a 3x3 rotation matrix
( A B C
   D E F
   G H I )

into povray, it's "simply"

( A B C
   D E F
   G H I
   0 0 0 )

With A to I being the naughty variations of 
"cos(phi)*sin(theta)*cos(gamma)" as usual.

To get the inverse matrix, I'm lazy:

#declare Forward = transform { matrix < .... > } };
#declare Backward = transform { Forward inverse };

As long as the forward matrix is not degenerated, that should do the job.


Post a reply to this message

From: Le Forgeron
Subject: Re: Get Euler angles from unit vector?
Date: 28 Sep 2018 02:53:23
Message: <5badcfe3$1@news.povray.org>
Le 28/09/2018 à 01:40, Mike Horvath a écrit :
> It would be nice to be able to set vector components like this:
> 
>      #local tPrjB1.z = max(min(tPrjB1.z,1),-1);
> 
> Are there any plans to do this in the future?
> 
> 
> 
> Mike

you could use the following:

#local P = <p.x, P.y, max(min(P.z),1),-1)>;

Make that a set of macro, and voila.

#macro BoundZ( V )
<V.x, V.y, max(min(V.z),1),-1) >
#end

#local P = BoundZ(P);


Post a reply to this message

<<< Previous 3 Messages Goto Initial 10 Messages

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