POV-Ray : Newsgroups : povray.advanced-users : REQ: reorienting a vector Server Time
4 Nov 2024 19:17:36 EST (-0500)
  REQ: reorienting a vector (Message 1 to 8 of 8)  
From: Margus Ramst
Subject: REQ: reorienting a vector
Date: 24 Apr 1999 22:35:23
Message: <3722715b.0@news.povray.org>
Hey all you math-enabled people!
I need a macro to give me the rotation vector to rotate vector A to have the
same direction as vector B. I suspect I could do it myself, but could
somebody spare me the head-ache?

Margus


Post a reply to this message

From: Ronald L  Parker
Subject: Re: REQ: reorienting a vector
Date: 24 Apr 1999 22:44:43
Message: <372271a9.213964711@news.povray.org>
On Sun, 25 Apr 1999 04:33:36 +0300, "Margus Ramst"
<mar### [at] peakeduee> wrote:

>Hey all you math-enabled people!
>I need a macro to give me the rotation vector to rotate vector A to have the
>same direction as vector B. I suspect I could do it myself, but could
>somebody spare me the head-ache?

John VanSickle's Thoroughly Useful Macros will help with this.  A copy
of the one you need can be found at http://twysted.net/macroscope


Post a reply to this message

From: Margus Ramst
Subject: Re: REQ: reorienting a vector
Date: 24 Apr 1999 23:02:54
Message: <372277ce.0@news.povray.org>
Ronald L. Parker wrote in message <372271a9.213964711@news.povray.org>...
>
>John VanSickle's Thoroughly Useful Macros will help with this.  A copy
>of the one you need can be found at http://twysted.net/macroscope
>

I don't think so. The Reorient macro is close, but it uses matrix
transformation to reorient an object. What I need is a rotation vector I
could use in vrotate().

Margus


Post a reply to this message

From: Ronald L  Parker
Subject: Re: REQ: reorienting a vector
Date: 24 Apr 1999 23:21:19
Message: <372379f4.216088045@news.povray.org>
On Sun, 25 Apr 1999 05:01:07 +0300, "Margus Ramst"
<mar### [at] peakeduee> wrote:

>Ronald L. Parker wrote in message <372271a9.213964711@news.povray.org>...
>>
>>John VanSickle's Thoroughly Useful Macros will help with this.  A copy
>>of the one you need can be found at http://twysted.net/macroscope
>>
>
>I don't think so. The Reorient macro is close, but it uses matrix
>transformation to reorient an object. What I need is a rotation vector I
>could use in vrotate().

Ah, okay, that's actually how I read it at first, but I couldn't
imagine why you would need such a thing so then I assumed that you
really wanted the Reorient macro.  I can get you an angle and an axis,
which you can use with vaxis_rotate(), if you'd like.  This isn't
tested, so it may be faulty.  In particular, you may have to fix the
sign on the angle. (It's times like this that I don't trust a
left-handed coordinate system.)  You may, of course, get rid of all
the intermediate local variables and make this a one-liner.

#macro vvec_rotate( Vec, RefA, RefB )
  #local nA = vnormalize(RefA);
  #local nB = vnormalize(RefB);
  #local axis = vcross(nA,nB);
  #local angle = degrees(atan2(vlength(axis),vdot(nA,nB)));
  vaxis_rotate( Vec, axis, angle );
#end


Post a reply to this message

From: Johannes Hubert
Subject: Re: reorienting a vector
Date: 25 Apr 1999 04:15:15
Message: <3722c103.0@news.povray.org>
Margus Ramst wrote in message <3722715b.0@news.povray.org>...
>Hey all you math-enabled people!
>I need a macro to give me the rotation vector to rotate vector A to have
the
>same direction as vector B. I suspect I could do it myself, but could
>somebody spare me the head-ache?


Interrupt me if I am wrong ;-) but do I understand you correctly?

You want to rotate a vector such, that it points in the same direction as
some other vector?

If so, I don't see the need for any rotational math. I would do it like
this:

Compute the length of vector A.
    lengthA = sqrt(Ax*Ax + Ay*Ay + Az*Az)

Normalize B to length 1. (B')
    lengthB = sqrt(Bx*Bx + Ay*Ay + Az*Az)
    B' = [ Bx/lengthB  By/lengthB  Bz/lengthB ]

Multiply it with the length of A (B'')
    B''= [ B'x*lengthA B'y*lengthA Bz*lengthA ]

B'' is now the same direction as B and with the length of A.

All in one formula:

            [ Bx / lengthB * lengthA ]
            [                        ]
   B'' =    [ By / lengthB * lengthA ]
            [                        ]
            [ Bz / lengthB * lengthA ]

(where lengthA and lengthB as given above)


Is that what you want?


Johannes.

P.S. So, I'm showing my math in public? I *really* hope I got it right ;-)


Post a reply to this message

From: Margus Ramst
Subject: Re: REQ: reorienting a vector
Date: 25 Apr 1999 09:31:41
Message: <37230b2d.0@news.povray.org>
Thank you, this is perfect.
One of these days I'm sure I'll learn to use vdot... Maybe. I hope.

Margus

Ronald L. Parker wrote in message <372379f4.216088045@news.povray.org>...
>
>Ah, okay, that's actually how I read it at first, but I couldn't
>imagine why you would need such a thing so then I assumed that you
>really wanted the Reorient macro.  I can get you an angle and an axis,
>which you can use with vaxis_rotate(), if you'd like.  This isn't
>tested, so it may be faulty.  In particular, you may have to fix the
>sign on the angle. (It's times like this that I don't trust a
>left-handed coordinate system.)  You may, of course, get rid of all
>the intermediate local variables and make this a one-liner.
>
>#macro vvec_rotate( Vec, RefA, RefB )
>  #local nA = vnormalize(RefA);
>  #local nB = vnormalize(RefB);
>  #local axis = vcross(nA,nB);
>  #local angle = degrees(atan2(vlength(axis),vdot(nA,nB)));
>  vaxis_rotate( Vec, axis, angle );
>#end
>
>


Post a reply to this message

From: Margus Ramst
Subject: Re: reorienting a vector
Date: 25 Apr 1999 09:32:11
Message: <37230b4b.0@news.povray.org>
Thanks. You understood correctly a somewhat incomplete explanation. What I
really needed was to rotate vector A by the same amount that base vector B
differs from new vector C (hope this makes sense). Ron seems to have divined
my purpose, so I have the answer.

BTW, you could've written

vlength(A)*vnormalize(B)

Trust me, I woud have understood :)

Margus

Johannes Hubert wrote in message <3722c103.0@news.povray.org>...
>
>Interrupt me if I am wrong ;-) but do I understand you correctly?
>
>You want to rotate a vector such, that it points in the same direction as
>some other vector?
>
>If so, I don't see the need for any rotational math. I would do it like
>this:
>
>Compute the length of vector A.
>    lengthA = sqrt(Ax*Ax + Ay*Ay + Az*Az)
>
>Normalize B to length 1. (B')
>    lengthB = sqrt(Bx*Bx + Ay*Ay + Az*Az)
>    B' = [ Bx/lengthB  By/lengthB  Bz/lengthB ]
>
>Multiply it with the length of A (B'')
>    B''= [ B'x*lengthA B'y*lengthA Bz*lengthA ]
>
>B'' is now the same direction as B and with the length of A.
>
>All in one formula:
>
>            [ Bx / lengthB * lengthA ]
>            [                        ]
>   B'' =    [ By / lengthB * lengthA ]
>            [                        ]
>            [ Bz / lengthB * lengthA ]
>
>(where lengthA and lengthB as given above)
>
>
>Is that what you want?
>
>
>Johannes.
>
>P.S. So, I'm showing my math in public? I *really* hope I got it right ;-)
>
>
>


Post a reply to this message

From: Matt Giuer
Subject: Re: REQ: reorienting a vector
Date: 26 Apr 1999 00:39:07
Message: <3723DFEC.8D22575@ij.net>
Margus Ramst wrote:
> 
> Hey all you math-enabled people!
> I need a macro to give me the rotation vector to rotate vector A to have the
> same direction as vector B. I suspect I could do it myself, but could
> somebody spare me the head-ache?

	subtract?


Post a reply to this message

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