POV-Ray : Newsgroups : povray.advanced-users : Get Euler angles from unit vector? : Re: Get Euler angles from unit vector? Server Time
25 Apr 2024 02:41:20 EDT (-0400)
  Re: Get Euler angles from unit vector?  
From: Mike Horvath
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

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