POV-Ray : Newsgroups : povray.advanced-users : Rotation Matrix around X or Y axis Actual vs. Theoretical Server Time
28 Jul 2024 16:19:30 EDT (-0400)
  Rotation Matrix around X or Y axis Actual vs. Theoretical (Message 1 to 7 of 7)  
From: amjad
Subject: Rotation Matrix around X or Y axis Actual vs. Theoretical
Date: 6 Sep 2004 14:40:00
Message: <web.413cae2697efafa9dba5e0750@news.povray.org>
When rotating a camera placed at <0,0,-z> with rotate  <0, y-Angel, > the
produced image behave different than what should I get if Using a Matrix
[cos 0 sin ; 0 1 0; -sin 0 cos] (Typical Single Rotation around Y axis).
The Matrix indicates that the y-coordinate should not change, but What I'm
getting on screen rendering is a change in the <x,y> coordinate? What is
the way in predicting the exact pixel location for an object -say a simple
box place at <x1,y1,z1> - in the image for rotating just the camera? Any
hint or help in this matter is really appreciated. In real life camera is a
simple panning or tilting can be represented using the simple single
rotation matrices? or there will be other parameters that are skipping me?


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: Rotation Matrix around X or Y axis Actual vs. Theoretical
Date: 6 Sep 2004 18:17:53
Message: <413ce211@news.povray.org>
amjad wrote:

> When rotating a camera placed at <0,0,-z> with rotate  <0, y-Angel, > the
> produced image behave different than what should I get if Using a Matrix
> [cos 0 sin ; 0 1 0; -sin 0 cos] (Typical Single Rotation around Y axis).
> The Matrix indicates that the y-coordinate should not change, but What I'm
> getting on screen rendering is a change in the <x,y> coordinate? What is
> the way in predicting the exact pixel location for an object -say a simple
> box place at <x1,y1,z1> - in the image for rotating just the camera? Any
> hint or help in this matter is really appreciated. In real life camera is a
> simple panning or tilting can be represented using the simple single
> rotation matrices? or there will be other parameters that are skipping me?


Amjad, please have a look at the code below.

Transformation of cameras works as expected.

Just remember that POV-Ray uses a left handed coordinate
system and that trigonometric functions takes radians as
arguments, while the rotate transformation expects a
rotation vector with components in degrees.


Tor Olav

P.S.: Questions like these belong in the povray.newusers group.


// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

#version 3.6;

#include "colors.inc"

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

box {
   -<1, 1, 1>, <1, 1, 1>
   pigment { color rgb <1, 1, 1> }
}

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

#declare Camera1 =
   camera {
     location <0, 0, -4> // or location -4*z
     look_at <0, 0, 0>   // ot look_at 0*y
     rotate <0, 30, 0>   // or rotate 30*y
   }

#declare Angle = radians(30);

#declare Camera2 =
   camera {
     location -4*z
     look_at 0*y
     matrix <
       cos(Angle), 0, -sin(Angle),
                0, 1,           0,
       sin(Angle), 0,  cos(Angle),
                0, 0,           0
     >
   }

camera { Camera1 }
//camera { Camera2 }

light_source { <1, 2, -3>*100 color rgb <1, 1, 1> }

background { color rgb <0.9, 0.8, 0.7> }

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: Rotation Matrix around X or Y axis Actual vs. Theoretical
Date: 6 Sep 2004 20:03:31
Message: <413cfad3$1@news.povray.org>
amjad wrote:
...
> In real life camera is a simple panning or tilting can be represented
> using the simple single rotation matrices?
...

The code below will do that for a perspective camera.

Tor Olav


// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
// Panning, Tilting and Rolling a perspective camera
// By Tor Olav Kristensen, 7. September 2004

#version 3.6;

#include "colors.inc"
#include "transforms.inc"

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
// Something to look at

#declare pBoxCornerA = <1, 2, 1>;
#declare pBoxCornerB = <2, 3, 2>;

box {
   pBoxCornerA, pBoxCornerB
   pigment { color White }
}

#declare pBoxCenter = (pBoxCornerA + pBoxCornerB)/2;

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

// Default camera parameters
#declare pLocation = 0*y;
#declare vDirection = z;
#declare vRight = 1.33*x;
#declare vUp = y;
#declare vSky = y;

/*
#declare DefaultCamera =
   camera {
     perspective
     location pLocation
     direction vDirection
     right vRight
     up vUp
     sky vSky
   }
*/

// Where to look from and where to look
#declare pLocation = <1, 2, -3>*2;
#declare pLookAt = pBoxCenter;

/*
// If POV-Ray where to calculate the new camera vectors
#declare LookAtCamera =
   camera {
     location pLocation
     look_at pLookAt
   }
*/

// Calculate the new camera vectors "manually"
#declare vLookAt = pLookAt - pLocation;
#declare vDirection = vlength(vDirection)*vnormalize(vLookAt);
#declare vRight = vlength(vRight)*vnormalize(vcross(vSky, vDirection));
#declare vUp = vlength(vUp)*vnormalize(vcross(vDirection, vRight));

#declare LookAtCamera =
   camera {
     location pLocation
     direction vDirection
     right vRight
     up vUp
   }

#declare Angle = 20; // Degrees

#declare PannedCamera =
   camera {
     LookAtCamera
     translate -pLocation
     Axis_Rotate_Trans(vUp, Angle)
     translate pLocation
   }

#declare TiltedCamera =
   camera {
     LookAtCamera
     translate -pLocation
     Axis_Rotate_Trans(vRight, Angle)
     translate pLocation
   }

#declare RolledCamera =
   camera {
     LookAtCamera
     translate -pLocation
     Axis_Rotate_Trans(vDirection, Angle)
     translate pLocation
   }

camera { LookAtCamera }
//camera { TiltedCamera }
//camera { PannedCamera }
//camera { RolledCamera }

light_source { <1, 2, -3>*100 color White }

background { color Blue/2 }

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: Rotation Matrix around X or Y axis Actual vs. Theoretical
Date: 6 Sep 2004 22:08:10
Message: <413d180a$1@news.povray.org>
amjad wrote:

...
> What is the way in predicting the exact pixel location for an object
> -say a simple box place at <x1,y1,z1> - in the image for rotating just 
> the camera? Any hint or help in this matter is really appreciated.
...

Below is some code that will find screen coordinates of a
point when the camera vectors are known.

If you do not know how to find the new camera vectors after
a camera rotation, then I can help you with this too.


Tor Olav


// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
// Calculation of screen coordinates of a point
// in front of a perspective camera.
// By Tor Olav Kristensen, 7. September 2004

#version 3.6;

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

#default {
   texture {
     pigment { color rgbt <0.5, 0.5, 0.5, 0.8> }
     finish { ambient 2 }
   }
}

background { color blue 0.5 }

// Default camera parameters
#declare pLocation = 0*y;
#declare vDirection = z;
#declare vRight = 1.33*x;
#declare vUp = y;
#declare vSky = y;

// Where to look from and where to look
#declare pLocation = <0, 2, -3>*4;
#declare pLookAt = <0, 3, 0>;

// Calculate the new camera vectors "manually"
#declare vLookAt = pLookAt - pLocation;
#declare vDirection = vlength(vDirection)*vnormalize(vLookAt);
#declare vRight = vlength(vRight)*vnormalize(vcross(vSky, vDirection));
#declare vUp = vlength(vUp)*vnormalize(vcross(vDirection, vRight));

camera {
   location pLocation
   direction vDirection
   right vRight
   up vUp
}

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

#declare vImageSize = <image_width, image_height>;

#declare p0 = <2, -1, 3>; // Position of sphere


#declare v0 = p0 - pLocation;

#declare vC =
   v0*vdot(vDirection, vDirection)/vdot(v0, vDirection);

#declare vImage =
   vImageSize*
   <
     vdot(vC, vRight)/vdot(vRight, vRight),
     vdot(vC, vUp)/vdot(vUp, vUp)
   >;

#debug "\n\n"
#debug "Position relative to center of image: "
#debug concat("<", vstr(2, vImage, ", ", 0, -1), ">")
#debug "\n"
#debug "Position relative to upper left corner of image: "
#declare vImage = vImageSize/2 + vImage*<1, -1>;
#debug concat("<", vstr(2, vImage, ", ", 0, -1), ">")
#debug "\n\n"

sphere {
   p0, 0.3
   pigment { color rgbt <0.8, 0.5, 0.5, 0.8> }
}

sphere {
   pLocation + vC*1, 0.01
   pigment { color rgbt <0.5, 0.8, 0.5, 0.8> }
}

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7


Post a reply to this message

From: amjad
Subject: Re: Rotation Matrix around X or Y axis Actual vs. Theoretical
Date: 20 Sep 2004 11:45:00
Message: <web.414efa7dde261ccadba5e0750@news.povray.org>
Tor Olav Kristensen <tor### [at] TOBEREMOVEDgmailcom> wrote:
> amjad wrote:
>
> Thanks for the fast reply. When we have the camera at <0,0,-z> and we do a simple
rotation i.e. around X-axis, the si
mple rotation matrix indicate that all x coordinate  will stay the same! But in
reality, a parallel street will converg
e to a point far away, thus the x-coordinates are changing as well as the
y-coordinate. The affine Matrix [1 0 0;0 cos 

e a way to represent this perspective rotation in a single matrix


Post a reply to this message

From: Slime
Subject: Re: Rotation Matrix around X or Y axis Actual vs. Theoretical
Date: 20 Sep 2004 13:04:02
Message: <414f0d82$1@news.povray.org>
> When rotating a camera placed at <0,0,-z> with rotate  <0, y-Angel, > the
> produced image behave different than what should I get if Using a Matrix
> [cos 0 sin ; 0 1 0; -sin 0 cos] (Typical Single Rotation around Y axis).

<0, y-angle, 0> is not a valid vector; it's equivalent to <0, <0,1,0> -
angle, 0> which doesn't make any sense. So I have to wonder, what does the
actual code that you're having trouble with look like? As you say, rotating
around the y-axis should not change the y-coordinate of any object,
including the camera. Why don't you show us your camera declaration, just in
case you're making a subtle mistake and not realizing it?

 - Slime
 [ http://www.slimeland.com/ ]


Post a reply to this message

From: Warp
Subject: Re: Rotation Matrix around X or Y axis Actual vs. Theoretical
Date: 21 Sep 2004 06:54:12
Message: <41500854@news.povray.org>
amjad <amj### [at] okstateedu> wrote:
> > Thanks for the fast reply. When we have the camera at <0,0,-z> and we do a simple
rotation i.e. around X-axis, the si
> mple rotation matrix indicate that all x coordinate  will stay the same! But in
reality, a parallel street will converg
> e to a point far away, thus the x-coordinates are changing as well as the
y-coordinate.

  X-coordinates are not changing, Z-coordinates are, which causes some
points to end up closer to the camera and other points to be farther
from the camera than originally, thus causing perspective distortion.

  This is exactly what rotation does. If you want to do something else,
you should be more specific.

-- 
#macro N(D)#if(D>99)cylinder{M()#local D=div(D,104);M().5,2pigment{rgb M()}}
N(D)#end#end#macro M()<mod(D,13)-6mod(div(D,13)8)-3,10>#end blob{
N(11117333955)N(4254934330)N(3900569407)N(7382340)N(3358)N(970)}//  - Warp -


Post a reply to this message

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