|
|
My head is spinning. I have a fairly simple task:
V1 = 0,1,0 (this is a vector pointing up along y-axis)
V2 = user defined unit vector pointing anywhere.
How do I rotate V1 using rotateX(), rotateY() and rotateZ() so that it
equals V2?
This would be intersting, too:
What is the resulting 4x4 transformation matrix that does the same thing?
Actually, I'd prefer just the transformation matrix because I guess I
could avoid using trigonometric functions back and forth.
Thanks,
Severi S.
Post a reply to this message
|
|
|
|
Severi Salminen <sev### [at] notthissaunalahtifiinvalid> wrote:
> My head is spinning. I have a fairly simple task:
> V1 = 0,1,0 (this is a vector pointing up along y-axis)
> V2 = user defined unit vector pointing anywhere.
> How do I rotate V1 using rotateX(), rotateY() and rotateZ() so that it
> equals V2?
> This would be intersting, too:
> What is the resulting 4x4 transformation matrix that does the same thing?
> Actually, I'd prefer just the transformation matrix because I guess I
> could avoid using trigonometric functions back and forth.
You can find it in transform.inc, as the PointAt() macro.
--
- Warp
Post a reply to this message
|
|
|
|
Severi Salminen wrote:
> My head is spinning. I have a fairly simple task:
>
> V1 = 0,1,0 (this is a vector pointing up along y-axis)
> V2 = user defined unit vector pointing anywhere.
>
> How do I rotate V1 using rotateX(), rotateY() and rotateZ() so that it
> equals V2?
>
> This would be intersting, too:
>
> What is the resulting 4x4 transformation matrix that does the same thing?
>
> Actually, I'd prefer just the transformation matrix because I guess I
> could avoid using trigonometric functions back and forth.
You are right: No trigonometric functions are needed.
Below is a rewritten version of the Reorient_Trans() macro.
Follow up set to povray.general
--
Tor Olav
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
// Copyright 2008 Tor Olav Kristensen
// http://subcube.com
// Rewrite of the Reorient_Trans() macro
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
#version 3.6;
#include "colors.inc"
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
#macro Reorient_Trans(v1, v2)
#local v1n = vnormalize(v1);
#local v2n = vnormalize(v2);
#local vA = vcross(v1n, v2n);
#local Sin = vlength(vA);
#local Cos = vdot(v1n, v2n);
#local M = 1 - Cos;
#local vAn = vnormalize(vA);
#local X = vAn.x;
#local Y = vAn.y;
#local Z = vAn.z;
transform {
matrix <
X*X*M + Cos, Y*X*M + Z*Sin, Z*X*M - Y*Sin,
X*Y*M - Z*Sin, Y*Y*M + Cos, Z*Y*M + X*Sin,
X*Z*M + Y*Sin, Y*Z*M - X*Sin, Z*Z*M + Cos,
0, 0, 0
>
}
#end // macro Reorient_Trans
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
#declare pA = <3, 2, -4>;
#declare pB = <2, 3, -2>;
//#declare pB = pA;
//#declare pB = -pA;
sphere {
<0, 0, 0>, 0.1
pigment { color White }
}
sphere {
pA, 0.1
pigment { color Blue }
}
sphere {
pB, 0.1
pigment { color Red }
}
object {
cylinder { <0, 0, 0>, pA, 0.05 }
Reorient_Trans(pA, pB)
pigment { color Yellow }
}
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
background { color Gray40 }
light_source {
<-1, 3, -2>*100
colour White*2
}
camera {
location <-1, 1, -1>*8
look_at 0*y
}
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
Post a reply to this message
|
|