POV-Ray : Newsgroups : povray.off-topic : Rotating vectors in 3D Server Time
6 Sep 2024 19:22:17 EDT (-0400)
  Rotating vectors in 3D (Message 1 to 6 of 6)  
From: Severi Salminen
Subject: Rotating vectors in 3D
Date: 12 Oct 2008 13:30:30
Message: <48f23436$1@news.povray.org>
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

From: Warp
Subject: Re: Rotating vectors in 3D
Date: 12 Oct 2008 13:33:06
Message: <48f234d1@news.povray.org>
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

From: Darren New
Subject: Re: Rotating vectors in 3D
Date: 12 Oct 2008 14:46:12
Message: <48f245f4$1@news.povray.org>
Severi Salminen wrote:
> My head is spinning. I have a fairly simple task:

Hey, take it to on-topic. ;-)

-- 
Darren New / San Diego, CA, USA (PST)


Post a reply to this message

From: Severi Salminen
Subject: Re: Rotating vectors in 3D
Date: 13 Oct 2008 03:25:57
Message: <48f2f805@news.povray.org>
Warp wrote:

>   You can find it in transform.inc, as the PointAt() macro.


Yes, thanks, that did the job.


Post a reply to this message

From: Severi Salminen
Subject: Re: Rotating vectors in 3D
Date: 13 Oct 2008 03:26:41
Message: <48f2f831$1@news.povray.org>
Darren New wrote:
> Hey, take it to on-topic. ;-)

But this IS off-topic as this is actually not POVRay related. So I won't
go anywhere :)


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: Rotating vectors in 3D
Date: 13 Oct 2008 19:06:59
Message: <48f3d493$1@news.povray.org>
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

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