POV-Ray : Newsgroups : povray.general : an extraordinary rotation question Server Time
4 Nov 2024 19:16:22 EST (-0500)
  an extraordinary rotation question (Message 1 to 10 of 41)  
Goto Latest 10 Messages Next 10 Messages >>>
From: mysdn
Subject: an extraordinary rotation question
Date: 19 Jun 2009 06:10:00
Message: <web.4a3b62de84d4e97f8813d5ca0@news.povray.org>
Hello everybody,
 I'm new at this forum and very interested in ray tracing. Currently, I'm using
Povray for ray tracing. But I have a huge problem understanding its rotation
logic. Let's say I have 2 walls each 250 cm in length. Suppose we stand in
front of 1st wall and 2nd wall is attached to 1st on the right side. Now rotate
2nd wall 45 degrees AND it loses position, no more their tips are attached like
they should as an angled wall. The 2nd wall moves towards us and forward.

Obviously I don't understand rotation in povray, I do use povray for many things
for over a year but rotation always eluded me. I attached sample pov file at
http://ompf.org/forum/viewtopic.php?f=6&t=1343
If you take a look and show me some direction, I will be grateful. If you take a
look at sample, you will see it's not just a simple matter of placing objects by
just translate to <0,0,0> then rotate to .. then translate back to etc. Cause
final translation values are assigned by 2D API Piccolo. Thank you very much.

P:S This is for an app that writes SDL, so it's important.
I also read a lot about povray rotate keyword but still dont get it and I can be
considered pretty smart as the huge 2D-3D C# app I wrote will testify.

Any type of help will be greatly appreciated.
ibrahim dogan
Turkey


Post a reply to this message

From: Chris B
Subject: Re: an extraordinary rotation question
Date: 19 Jun 2009 11:08:31
Message: <4a3ba9ef@news.povray.org>
"mysdn" <kam### [at] hotmailcom> wrote in message 
news:web.4a3b62de84d4e97f8813d5ca0@news.povray.org...
> Hello everybody,
> I'm new at this forum and very interested in ray tracing. Currently, I'm 
> using
> Povray for ray tracing. But I have a huge problem understanding its 
> rotation
> logic. Let's say I have 2 walls each 250 cm in length. Suppose we stand in
> front of 1st wall and 2nd wall is attached to 1st on the right side. Now 
> rotate
> 2nd wall 45 degrees AND it loses position, no more their tips are attached 
> like
> they should as an angled wall. The 2nd wall moves towards us and forward.
>
> Obviously I don't understand rotation in povray, I do use povray for many 
> things
> for over a year but rotation always eluded me. I attached sample pov file 
> at
> http://ompf.org/forum/viewtopic.php?f=6&t=1343
> If you take a look and show me some direction, I will be grateful. If you 
> take a
> look at sample, you will see it's not just a simple matter of placing 
> objects by
> just translate to <0,0,0> then rotate to .. then translate back to etc. 
> Cause
> final translation values are assigned by 2D API Piccolo. Thank you very 
> much.
>
> P:S This is for an app that writes SDL, so it's important.
> I also read a lot about povray rotate keyword but still dont get it and I 
> can be
> considered pretty smart as the huge 2D-3D C# app I wrote will testify.
>

The standard 'rotate' operation rotates around the origin. In the case that 
you describe I think you'd need to rotate around the near left corner of the 
second wall (using that edge as a rotational axis). There is a macro in the 
"transforms.inc" file that comes with POV-Ray that will do this for you. So 
you'll need to add the line:

#include "transforms.inc"

Then you can use the "Rotate_Around_Trans(Rotation, Point)" macro in place 
of the current set of translations and rotations that you have at the end of 
your file 'rotation.pov'. You'll probably need something like the following 
code:

#declare Axis = min_extent(ek_duvar12);
object {ek_duvar12  Axis_Rotate_Trans( 45*y,Axis)}

This assumes that the point on the wall object that is furthest in the -x 
direction and the point the furthest in the -z direction adequately define 
the corner that you need to rotate around. The y value doesn't really matter 
if you're only rotating around y. However, if your wall has a rough surface, 
or protrusions such as buttresses, you may need to adjust Axis before 
passing it into the macro. You can do this by adding a vector to compensate 
for these protrusions. For example:

#declare Axis = Axis+<0.01,0,0.02>;


Regards,
Chris B.


Post a reply to this message

From: clipka
Subject: Re: an extraordinary rotation question
Date: 19 Jun 2009 14:30:00
Message: <web.4a3bd891cfb6d607080f32a0@news.povray.org>
"mysdn" <kam### [at] hotmailcom> wrote:
>  I'm new at this forum and very interested in ray tracing. Currently, I'm using
> Povray for ray tracing. But I have a huge problem understanding its rotation
> logic.

That's perfectly normal, I guess everyone had that :)

The key to understanding POV-Ray's rotations is that POV-Ray always (well,
*virtually* always) operates in absolute coordinate space; similarly, rotations
are always about the absolute coordinate origin.

In order to rotate an object around an arbitrary point, you need to first
translate the object so that the particular point ends up at the absolute
coordinate origin, then perform the rotation, and then translate the object
back; e.g.:

    translate -<3,2,1>
    rotate y*30
    translate <3,2,1>

will perform a 30-degree rotation about the vertical through the point <3,2,1>.


Post a reply to this message

From: mysdn
Subject: Re: an extraordinary rotation question
Date: 19 Jun 2009 17:35:01
Message: <web.4a3c0304cfb6d608813d5ca0@news.povray.org>
Thanks clipka and Chris B,

Chris, thanks for the explanations but transform.inc fails (yellow line) at the
second line of the macro   Axis_Rotate_Trans(Axis, Angle).

I can place objects precisely positioned when they are at 0-360, 90, 180, 270
degrees rotated by taking into account their width or height. If rotation is
0-360 or 180 I calculate width into positioning math. If rotation is 90 or 270
degrees I calculate height (or depth, speaking 2D) into positioning. And
everything is fine at those mentioned degrees of rotation. Trouble begins with
rotation values other than these.   Do I need trigonometry to calculate rotated
objects position, for example move it some points to the right or left for each
degree of object's rotation. Simply put the regular advice translate -<....>
then rotate y*45 then translate to final position doesnot work in this case. If
I knew why it didn't work maybe problem would be solved.
I bet there is a ready solution for this, Chris came close to putting his finger
on it.

I appreciate anyone's contribution, I'm reaaaaly stuck, maybe desperate. Thanks.

PS: povray version 3.6.1c


Post a reply to this message

From: Tim Attwood
Subject: Re: an extraordinary rotation question
Date: 19 Jun 2009 19:02:19
Message: <4a3c18fb@news.povray.org>
For exact alignments of object you need the
correct coordinates for the desired "seam" corner.
In the example you provided one of the corners is
at <-49.999,-49.999,0.001>, and another at
<50.001,50.001,100.001>.  

The first thing you are doing with "box_"
is redeclaring it as BOX.
#declare BOX = object { box_  scale <0.01,0.01,0.01> translate <0, 0, 0> }
When you scale you are relocating the corners around the origin by
multiplication. So 
0.01*<-49.999,-49.999,0.001> = <-0.5,-0.5,0>, and
0.01*<50.001,50.001,100.001> = <0.5,0.5,1>
Then translate <0,0,0> does nothing at all.

So then you have your first wall so you scale by
<250,260,10>... so
<250,260,10>*<-0.5,-0.5,0>= <-125,-130,0>, and
<250,260,10>*<0.5,0.5,1>=<125,130,10>
which you then translate... so addition
<-125,130,-3.5>+<-125,-130,0> = <-250,0,-3.5>, and
<-125,130,-3.5>+<125,130,10>=<0,260,6.5>
So the first wall is equivalent to 
box{<-250,0,-3.5>,<0,260,6.5>}

So then you have your second wall, which
you scale to size <200,260,15>
so now you have an equivalent
box {<-100,-130,0>,<100,130,15>}
Because BOX is siting on the origin, the center 
of the scaled box is still sitting on the origin,
but the corner you want to rotate around isn't.
So for this example I'll pick a corner... <-100,-130,0>
What you want to do is take that corner and
put it on the origin... so
translate <100,130,0>
then rotate it by some angle say 
rotate y*45
and then put that corner on a corner from the first
wall... say <-250,0,-3.5> so 
translate <-250,0,-3.5>

So to summarize, something like

// first wall
box{<-250,0,-3.5>,<0,260,6.5>}

// second wall
box {<-100,-130,0>,<100,130,15>
   translate <100,130,0>
   rotate y*45
   translate <-250,0,-3.5>
}

But where does that leave the other
corner of the second wall? Before we
rotated it we knew it was at <200,260,0>,
but there's math involved, that could get
complicated. Fortunately, POV has a function
to figure it out for us... vrotate....
so the other corner is at
vrotate(<200,260,0>,y*45)+<-250,0,-3.5>
So, for the third wall you'd translate it to there.


Post a reply to this message

From: mysdn
Subject: Re: an extraordinary rotation question
Date: 19 Jun 2009 20:10:00
Message: <web.4a3c279fcfb6d608813d5ca0@news.povray.org>
Tim,
I am grateful for helping me solve a problem that's been bothering me for more
than a year. I got it working, now I can concatenate 2 walls seamlessly at
given angles. A third wall as you mentioned would be a little problematic since
I'm weak on coordinate systems. I guess I must learn vrotate inside out.

I thank you very much again, I also appreciate Chris B and clipka's input.


Post a reply to this message

From: mysdn
Subject: Re: an extraordinary rotation question
Date: 19 Jun 2009 20:45:00
Message: <web.4a3c30cacfb6d608813d5ca0@news.povray.org>
Tim,

So then you have your first wall so you scale by
<250,260,10>... so
<250,260,10>*<-0.5,-0.5,0>= <-125,-130,0>, and
<250,260,10>*<0.5,0.5,1>=<125,130,10>
which you then translate... so addition
<-125,130,-3.5>+<-125,-130,0> = <-250,0,-3.5>, and
<-125,130,-3.5>+<125,130,10>=<0,260,6.5>
So the first wall is equivalent to
box{<-250,0,-3.5>,<0,260,6.5>}
--------------------------------------------

Where do you come up with the <-0.5,-0.5,0> for multiplication. Why do you
sometimes add then multiply? Where specifically can I learn more about matrix
manipulations in povray? Sorry for being a burden, Thank you.


Post a reply to this message

From: Tim Attwood
Subject: Re: an extraordinary rotation question
Date: 19 Jun 2009 22:29:21
Message: <4a3c4981$1@news.povray.org>
> Where do you come up with the <-0.5,-0.5,0> for multiplication. 

<-0.5,-0.5,0> is the coordinate of of the lower-left-forward corner
of the BOX mesh, which is the _box mesh <-49.999,-49.999,0.001>
scaled by 0.01 (and rounded a bit).

> Why do you sometimes add then multiply? 

Addition is equivalent to translation.
So if you have a point at coordinate A and 
translate it by amount B the point is now at
coordinate A+B.

Scaling is equavalent to multiplication.
So if you have a point at coordinate A and 
scale it by amount B, the point is now at 
coordinate A*B. 

You need to be careful with scaling, for
example if you have box{<1,1,1>,<2,2,2>}
and want to triple the size of the box, you
might just scale <3,3,3>, that triples the
size of the box fine, but now it's equivalent
to box{<3,3,3>,<6,6,6>}... it's now moved.
To keep the corner at <1,1,1> you need to
move it to the origin, scale, then put it back. 

>Where specifically can I learn more about matrix 
>manipulations in povray? 

Matrix transforms in POV are equivalent to
multiplying a vector by a 4x4 matrix. The
4th column is assumed to be 0 0 0 1.
Matrix math is covered in linear algebra in
college, I think. The bits to know for POV are...

(1) not all matrix tranforms result in a
valid transform, you could get errors if
you feed it nonsense numbers.

(2) given a matrix (POV docs 2.2.7.1.4) 
matrix <Val00, Val01, Val02,
        Val10, Val11, Val12,
        Val20, Val21, Val22,
        Val30, Val31, Val32>
the result if applied to a point P=<px,py,pz>
is a point Q=<qx,qy,qz> where
qx = Val00 * px + Val10 * py + Val20 * pz + Val30 
qy = Val01 * px + Val11 * py + Val21 * pz + Val31 
qz = Val02 * px + Val12 * py + Val22 * pz + Val32 

(3) a surface of an object is actually a set of points,
so a matrix transform applied to an object moves
all the points (it moves the object). It could scale, 
rotate, and translate, or some form of all three.
Most importantly, it can shear.

(4) Val30, Val31, Val32 (row 4) in a matrix transform
represents a translatation value.

(5) Val00, Val01, Val02  (row 1) in a matrix transform
represents the desired new X direction.

(6) Val10, Val11, Val12  (row 2) in a matrix transform
represents the desired new Y direction.

(7) Val20, Val21, Val22 (row 3) in a matrix transform
represents the desired new Z direction.

(8) The magnitude of the direction "vectors" (5-7) control
scaling.

(9) If you have a matrix transform T1 and a matrix transform
T2, then applying T1 and then T2 to an object is equivalent
to applying a transform T3=T1*T2, with some moderately 
complicated matrix multiplication rules. In other words,
behind the scenes, the list of transforms (translate, rotate, 
scale, matrix) that you feed to an object in POV are reduced 
to a single transform during the parse phase, no matter how
many transforms you use, they're a fixed (per object) cost.

>Sorry for being a burden, Thank you.

No problem.


Post a reply to this message

From: Larry Hudson
Subject: Re: an extraordinary rotation question
Date: 19 Jun 2009 23:42:23
Message: <4a3c5a9f$1@news.povray.org>
mysdn wrote:
> Hello everybody,
>  I'm new at this forum and very interested in ray tracing. Currently, I'm using
> Povray for ray tracing. But I have a huge problem understanding its rotation
...
> Any type of help will be greatly appreciated.
> ibrahim dogan
> Turkey

You have already received far more detailed explanations, so I don't 
know if this is helpful or not.  This is a VERY simple demo of rotations 
and scaling.  And being simple, it might help you visualize how POV-Ray 
handles these things.  The key to remember, ALL rotations and scalings 
are done with respect to the coordinate axes.

This image uses a simple 2-unit box created centered around the origin, 
then rotated/scaled/translated in various ways.

Rotated around z then translated along x (blue)
Translated along x then rotated around z (cyan)
Scaled then translated along y (red)
Translated then scaled along y (magenta)

Then to show the order of the rotations is important...
Rotated around x then around y (yellow)
Rotated around y then around x (orange)

****************************************
#include "colors.inc"

camera {
     location <-2, 2.5, -15>
     look_at 0
}

light_source { <-5, 20, -30> White * 1.2 }

background { SkyBlue }

#declare Cube = box { -1, 1 }

#declare Axes = union {
     cylinder { <-100, 0, 0>, <100, 0, 0>, .05 }
     cylinder { <0, -100, 0>, <0, 100, 0>, .05 }
     cylinder { <0, 0, -100>, <0, 0, 100>, .05 }
     pigment { Gray70 }
     no_shadow
}

object {    //  Rotate followed by translate
     Cube pigment { Blue }
     rotate z * 45
     translate x * 5
}

object {    //  Translate followed by rotate
     Cube pigment { Cyan }
     translate x * 5
     rotate z * 45
}

object {    //  Scale followed by translate
     Cube pigment { Red }
     scale .5
     translate y * 5
}

object {    //  Translate followed by scale
     Cube pigment { Magenta }
     translate y * 5
     scale .5
}

object {    //  Rotate x followed by rotate y
     Cube pigment { Yellow }
     rotate <45, 45, 0>
     translate -x * 6
}

object {    //  Rotate y followed by rotate x
     Cube pigment { Orange }
     rotate y * 45 rotate x * 45
     translate -x * 2
}

plane { y, -5 pigment { Green } }

//  Comment this out for no axes displayed
object { Axes }
*****************************************

Hope this helps.

      -=- Larry -=-


Post a reply to this message

From: mysdn
Subject: Re: an extraordinary rotation question
Date: 20 Jun 2009 05:30:01
Message: <web.4a3cab55cfb6d608813d5ca0@news.povray.org>
Tim, you astounded me by your beautifully detailed answer to my matrix question.
Thanks a million, I think I need a while to let it all sink in.

Larry, thanks for your explanation too, it's as if you read my mind by offering
the sample you did. Cause I was going to ask almost the exact same question
here. Suppose you have 3 kitchen cabinets placed side by side then you rotate
the one in the middle 45 degrees and it loses position again. It should rotate
in place but it ends up some off place, not as off as the wall sample I
offered, but a little off. I guess this is because of the wall's and cabinet's
widths are different.

In the wall sample, we rotated by picking a corner as base rotation point. HOW
would we rotate the cabinet in place? I do this in my app for a year now and it
always moves off a little, this in a commercial application looks very
unprofessional. I would like both Larry's and Tim's input, if possible, because
2 explanations explain more than one.

PS: I am 44 Turkish, married, no kids. my email is jestagu a t y a h o o
if you send me a note I would like to make friends with both of you people. If
you visit izmir-turkey I'd love to show you around, well maybe you heard of
turkish hospitality, I have some of that too.


Post a reply to this message

Goto Latest 10 Messages Next 10 Messages >>>

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