POV-Ray : Newsgroups : povray.general : Inverse of vrotate? Server Time: 23 Mar 2019 06:15:31 GMT
 Inverse of vrotate? (Message 1 to 5 of 5)
 From: Mike Horvath Subject: Inverse of vrotate? Date: 11 Mar 2018 00:10:33 Message: <5aa473f9\$1@news.povray.org>
```How do I do the opposite of the `vrotate` command? E.g. I have two
vectors, and need to know the <x,y,0> rotation angles to achieve the
latter from the former? Thanks!!

Mike
```
 From: dick balaska Subject: Re: Inverse of vrotate? Date: 11 Mar 2018 03:47:42 Message: <5aa4a6de\$1@news.povray.org>
```On 03/10/2018 07:10 PM, Mike Horvath wrote:
> How do I do the opposite of the `vrotate` command? E.g. I have two
> vectors, and need to know the <x,y,0> rotation angles to achieve the
> latter from the former? Thanks!!
>
>
> Mike

I just did this move.  I assume you are looking at one thing and want to
look at another.

_i runs from 0..1, the duration of the move
_f perturbs _i by adding acceleration/deceleration. Still 0..1
VtoA() converts to angle
r0,r1 start,end angles
MoveV interpolate between r0,r1 by _f

#local _i=AniSegment(StartTime, EndTime);
#local _f=Curve0(_i);
#local v0=StartVec;
#local v1=EndVec;
#local r0=VtoA(v0-Camera);
#local r1=VtoA(v1-Camera);
#local rot=MoveV(r0,r1,_f);
#declare Lookat=vrotate(<0,0,1>, rot)+Camera;

///////////////////////////////////////////////////////////////////////////////////////////////////
// Convert this vector into its angle in degrees
#macro VtoA(V)
#local _V=vnormalize(V);
#local rZ=degrees(acos(_V.z));
#local rY=0;
#local rX=0;
#if (_V.y != 0)
#local rY=degrees(atan2(_V.x,_V.y));
#else
#local rX=rZ;
#local rZ=0;
#end
<-rZ,-rX,-rY>
#end

///////////////////////////////////////////////////////////////////////////////////////////////////
// Move a Vector from, to, increment
#macro MoveV(_from, _to, __i)
<_from.x+((_to.x-_from.x)*__i),
_from.y+((_to.y-_from.y)*__i),
_from.z+((_to.z-_from.z)*__i)>
#end

///////////////////////////////////////////////////////////////////////////////////////////////////
#macro Curve0(_i)
(0.5-(cos(_i/2*pi2)/2))
#end
--
dik
Rendered 920576 of 921600 pixels (99%)
```
 From: Mike Horvath Subject: Re: Inverse of vrotate? Date: 11 Mar 2018 04:52:58 Message: <5aa4b62a\$1@news.povray.org>
```I am not getting the results I want.

#declare light_source_location	= vrotate(<0,0,-1>, <-060,-060,+000>);
#declare light_source_rotation	= VtoA(light_source_location);

#debug "\n"
#debug concat("angles = ", vstr(3, light_source_rotation, ",", 0, -1), "\n")
#debug "\n"

The input and output angles do not match.

I would also rather omit the z angle in the result, so that there is
only rotation around the x and y axes.

Mike
```
 From: Mike Horvath Subject: Re: Inverse of vrotate? Date: 11 Mar 2018 06:16:09 Message: <5aa4c9a9\$1@news.povray.org>
```I forgot I did this once already.

Mike

#macro vanglesXY(tVec2)
#local fSgnX = 1;
#local fSgnY = 1;
#local tPrjB1 = vnormalize(<tVec2.x, 0, tVec2.z>);

#if (tPrjB1.x != 0)
#local fSgnX = tPrjB1.x/abs(tPrjB1.x) * -1;
#end

#local tPrjB1 = <tPrjB1.x, tPrjB1.y, max(min(tPrjB1.z,1),-1)>;
#local fAngY = acosd(tPrjB1.z) * fSgnX;
#local tPrjB2 = vnormalize(vrotate(tVec2, <0, fAngY, 0>));

#if (tPrjB2.y != 0)
#local fSgnY = tPrjB2.y/abs(tPrjB2.y);
#end

#local tPrjB2 = <tPrjB2.x, tPrjB2.y, max(min(tPrjB2.z,1),-1)>;
#local fAngX = acosd(tPrjB2.z) * fSgnY;
<fAngX, (fAngY + 180) * -1, 0>
#end
```
 From: dick balaska Subject: Re: Inverse of vrotate? Date: 11 Mar 2018 06:19:29 Message: <5aa4ca71\$1@news.povray.org>
```On 03/10/2018 11:53 PM, Mike Horvath wrote:
> I am not getting the results I want.

> #declare light_source_locationÂ Â Â  = vrotate(<0,0,-1>, <-060,-060,+000>);

You know that this statement always gives a vlength(1) vector? (<-1,0,0>
or <0,1,0>) It's going to be real close to the origin. I'm thinking
that's not what you want.

Are you trying to move a light on a curve between two points?  That is a
different thing than I presented.

> The input and output angles do not match.

They wouldn't with my formula.  y is always 0. It's confusing to eyeball
"How can y be 0 when I'm clearly rotating 90 degrees around y". But
twiddling x/z gets you to the same place.

>
> I would also rather omit the z angle in the result, so that there is
> only rotation around the x and y axes.

You can build it as two separate x,y rotations if you know how to
degrees(atan2(V.y, V.z))

>
>
> Mike

--
dik
Rendered 920576 of 921600 pixels (99%)
```