|
|
|
|
|
|
| |
| |
|
|
|
|
| |
| |
|
|
How do I convert a matrix, or just 3 vectors, into a rotation vector?
If I have a matrix where the x, y, and z vectors are all perpendicular to
each other, and left-handed, and there's no translation, how do I find out
which rotate statement will transform my object in the same way as the
matrix?
For example
matrix <0,0,-1,0,1,0,1,0,0,0,0,0>
will produce the same result as
rotate <0,90,0>
I need a function that can convert any matrix (or just 3 vectors) that
follows the requirements into a rotate vector. How could that be done? Is it
possible at all?
Greetings,
Rune
---
Updated April 25: http://rsj.mobilixnet.dk
Containing 3D images, stereograms, tutorials,
The POV Desktop Theme, 350+ raytracing jokes,
miscellaneous other things, and a lot of fun!
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
On Fri, 19 May 2000 15:44:29 +0200, "Rune" <run### [at] inamecom>
wrote:
>How do I convert a matrix, or just 3 vectors, into a rotation vector?
>I need a function that can convert any matrix (or just 3 vectors) that
>follows the requirements into a rotate vector. How could that be done? Is it
>possible at all?
A matrix can hold any affine transformation. Chances are very small
that your matrix is a rotational one. So briefly, I don't think it's
possible.
Peter Popov ICQ : 15002700
Personal e-mail : pet### [at] usanet
TAG e-mail : pet### [at] tagpovrayorg
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
"Peter Popov" wrote:
> "Rune" wrote:
>
> >How do I convert a matrix, or just 3 vectors,
> >into a rotation vector?
>
> >I need a function that can convert any matrix
> >(or just 3 vectors) that follows the
> >requirements into a rotate vector. How could
> >that be done? Is it possible at all?
>
> A matrix can hold any affine transformation.
> Chances are very small that your matrix is a
> rotational one. So briefly, I don't think it's
> possible.
I did say "that follows the requirements".
That is where the x, y, and z vectors are all perpendicular to each other,
and left-handed, and there's no translation.
So is there any way?
Greetings,
Rune
---
Updated April 25: http://rsj.mobilixnet.dk
Containing 3D images, stereograms, tutorials,
The POV Desktop Theme, 350+ raytracing jokes,
miscellaneous other things, and a lot of fun!
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Rune wrote:
> So is there any way?
If it is possible these two sites will tell you -
http://www.gate.net/~shipbrk/raytrace/matrix.html
http://www.erols.com/vansickl/matrix.htm
--
Ken Tyler - 1400+ POV-Ray, Graphics, 3D Rendering, and Raytracing Links:
http://home.pacbell.net/tylereng/index.html http://www.povray.org/links/
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
"Ken" wrote:
> Rune wrote:
> > So is there any way?
>
> If it is possible these two sites will tell you -
>
> http://www.gate.net/~shipbrk/raytrace/matrix.html
> http://www.erols.com/vansickl/matrix.htm
No of those pages explain how to do what I want to do, although the second
one comes close. But thanks for the links anyway! :-)
I found the solution of my problem myself.
The first macro is just a macro needed by the second macro.
The second macro do what I wanted to do.
// FindAngle will find the angle between V1 and V2.
// The third parameter "About" is a vector which must be
// perpendicular to both V1 and V2. If the rotation from
// V1 to V2 about "About" is negative, the returned angle
// is negative. ( When you look in the direction of "About"
// clockwise is negative and anticlockwise is positive. )
// If you set "about" to <0,0,0> the returned angle will
// always be positive (or zero).
#macro FindAngle (V1,V2,About) // by Rune S. Johansen
#local Angle = degrees(acos(vdot(vnormalize(V1),vnormalize(V2))));
#if (
(vlength(About)!=0)
&
(vlength(vaxis_rotate(V1,-About,Angle)-V2)<vlength(vaxis_rotate(V1,About,Ang
le)-V2))
)
#local Angle = -Angle;
#end
Angle
#end
// Given 2 vectors, a vector for the X direction
// (similar to the 1st - 3rd number in a matrix),
// and one for the Y direction (similar to the
// 4th - 6th number in a matrix), Vectors2Rotate will
// return a rotation vector which will transform an
// object in the same way as a matrix using the
// vectors would do. VectorX and VectorY must be
// perpendicular to each other.
#macro Vectors2Rotate (VectorX,VectorY) // by Rune S. Johansen
#local RotZ = FindAngle(x,<VectorX.x,VectorX.y,0>,z);
#local RotY = FindAngle(x,vrotate(X,-RotZ*z),y);
#local RotX = FindAngle(vrotate(y,<0,RotY,RotZ>),VectorY,VectorX);
<RotX,RotY,RotZ>
#end
Greetings,
Rune
---
Updated April 25: http://rsj.mobilixnet.dk
Containing 3D images, stereograms, tutorials,
The POV Desktop Theme, 350+ raytracing jokes,
miscellaneous other things, and a lot of fun!
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Rune wrote:
8<..... snip .....
> The first macro is just a macro needed by the second macro.
> The second macro do what I wanted to do.
8<..... snip .....
>#macro FindAngle (V1,V2,About) // by Rune S. Johansen
> #local Angle = degrees(acos(vdot(vnormalize(V1),vnormalize(V2))));
> #if (
> (vlength(About)!=0)
> &
>(vlength(vaxis_rotate(V1,-About,Angle)-V2)<
> vlength(vaxis_rotate(V1,About,Angle)-V2)))
> #local Angle = -Angle;
> #end
> Angle
>#end
8<..... snip .....
>#macro Vectors2Rotate (VectorX,VectorY) // by Rune S. Johansen
> #local RotZ = FindAngle(x,<VectorX.x,VectorX.y,0>,z);
> #local RotY = FindAngle(x,vrotate(X,-RotZ*z),y);
> #local RotX = FindAngle(vrotate(y,<0,RotY,RotZ>),VectorY,VectorX);
> <RotX,RotY,RotZ>
>#end
8<..... snip .....
I think there must be an error in your second macro.
The variable X (in the 3rd line) is not defined.
Is this meant to be a lower case x ?
And I believe your first macro could be simplified to this:
#macro Find_Angle(v1, v2, vAbout)
(vdot(vAbout, vcross(v1, v2)) < 0 ? -1 : 1)*
degrees(acos(vdot(vnormalize(v1), vnormalize(v2))))
#end // macro FindAngle
This macro gives the Angle the same sign as the
Scalar Triple Product of your 3 vectors;
vAbout, v1 and v2
Regards,
Tor Olav
--
mailto:tor### [at] hotmailcom
http://www.crosswinds.net/~tok/tokrays.html
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
"Tor Olav Kristensen" wrote:
> I think there must be an error in your second macro.
> The variable X (in the 3rd line) is not defined.
> Is this meant to be a lower case x ?
No, it's supposed to be VectorX. Thank you for pointing it out.
This should be correct:
#macro Vectors2Rotate (VectorX,VectorY) // by Rune S. Johansen
#local RotZ = FindAngle(x,<VectorX.x,VectorX.y,0>,z);
#local RotY = FindAngle(x,vrotate(VectorX,-RotZ*z),y);
#local RotX = FindAngle(vrotate(y,<0,RotY,RotZ>),VectorY,VectorX);
<RotX,RotY,RotZ>
#end
> And I believe your first macro could be simplified to this:
<snipped code>
Hmm, you're probably right. I just write code using my own math skills,
which means that it is not always so optimized... I will have a look your
version.
Greetings,
Rune
---
Updated April 25: http://rsj.mobilixnet.dk
Containing 3D images, stereograms, tutorials,
The POV Desktop Theme, 350+ raytracing jokes,
miscellaneous other things, and a lot of fun!
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
On Sat, 20 May 2000 15:46:55 +0200, Rune wrote:
>"Ken" wrote:
>> Rune wrote:
>> > So is there any way?
>>
>> If it is possible these two sites will tell you -
>>
>> http://www.gate.net/~shipbrk/raytrace/matrix.html
>> http://www.erols.com/vansickl/matrix.htm
>
>No of those pages explain how to do what I want to do, although the second
>one comes close. But thanks for the links anyway! :-)
I once did the math to figure out how to turn a matrix into a rotation,
a scale, and a transform (provided it didn't have a significant skew
component.) If you still need it (not that it looks like you do) I can
email it to you or post it here.
--
Ron Parker http://www2.fwi.com/~parkerr/traces.html
These are my opinions. I do NOT speak for the POV-Team.
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
"Ron Parker" wrote:
> I once did the math to figure out how to turn a
> matrix into a rotation, a scale, and a transform
> (provided it didn't have a significant skew
> component.) If you still need it (not that it
> looks like you do) I can email it to you or post
> it here.
My own problem is solved now, but it would be very interesting to see your
solution anyway! Mine did the rotation part only.
> (provided it didn't have a significant skew
> component.)
You can do that with rotate, scale and translate too. Actually I would guess
that any transformation can be done using those. Not that I need it... :-)
Greetings,
Rune
---
Updated April 25: http://rsj.mobilixnet.dk
Containing 3D images, stereograms, tutorials,
The POV Desktop Theme, 350+ raytracing jokes,
miscellaneous other things, and a lot of fun!
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
On Mon, 22 May 2000 17:46:55 +0200, "Rune" <run### [at] inamecom>
wrote:
>> (provided it didn't have a significant skew
>> component.)
>
>You can do that with rotate, scale and translate too. Actually I would guess
>that any transformation can be done using those. Not that I need it... :-)
If you mean you can skew an object by rotation, translation and
scaling, I think you've been mislead. Mr. VanSickle is The One when it
comes to manipulating the matrix keyword and I trust whatever he says
on the subject, but this time I doubt he'd disagree. Then again, if I
am wrong, I will learn something new :)
Peter Popov ICQ : 15002700
Personal e-mail : pet### [at] usanet
TAG e-mail : pet### [at] tagpovrayorg
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
|
|