POV-Ray : Newsgroups : povray.newusers : determining location of an object that has been transformed and rotated Server Time
2 Nov 2024 01:21:29 EDT (-0400)
  determining location of an object that has been transformed and rotated (Message 1 to 5 of 5)  
From: Jeremiah Isaacs
Subject: determining location of an object that has been transformed and rotated
Date: 15 Sep 2004 15:55:01
Message: <web.41489cc265a1a06956b76d0d0@news.povray.org>
I have been hunting around for an answer to this (looking at everything from
vector() to spherical geometry pages), and at this point I am looking in
too many directions at once.   Some guidance would be appreciated.

// Lets say there is a vector
// (could be anything)
#declare SomeVector = <10, 20, 30>

// ..  and an object ...

sphere {
     0, 1

// and I translate it away from the origin

translate z*10

// then I rotate it

rotate SomeVector

}

Where is the center of the sphere after the transformations in <x,y,z>
coordinates?

Now, if I only rotate it by  <10, 20> I think I can figure it out with trig.
 However using all three has me slightly baffled.  I have been digging thru
math.inc, functions.inc, and transforms.inc, and haven't found a funtion to
do this.

And ffor the double whammy, what if I translate and rotate an object an
arbitrary number of times.  How to locate it?

Background:  I have been using povray for a long time, but never intensely.

Thanks - Jeremiah


Post a reply to this message

From: Slime
Subject: Re: determining location of an object that has been transformed and rotated
Date: 15 Sep 2004 16:13:24
Message: <4148a264$1@news.povray.org>
> Where is the center of the sphere after the transformations in <x,y,z>
> coordinates?

I'd like to answer that question in two ways. First in a high pitched voice,
and then in my regular voice. Heh, no but seriously; first I'll give you the
answer you were probably looking for, and then I'll tell you the more
practical trick to do what you want in POV-Ray.

Every translation corresponds to adding to the vector:

#declare spherepos = <0,0,0>;
sphere {spherepos, 1
translate <1,2,3>
#declare spherepos = spherepos + <1,2,3>;
}

Every scale corresponds to multiplying the vector:

scale <4,5,6>
#declare spherepos = spherepos * <4,5,6>;

Rotations are, as you've noticed, a bit more complicated. First, they can be
split into separate rotations around the x, y, and z axes:

rotate <3,4,5>
is equivalent to
rotate <3,0,0>
rotate <0,4,0>
rotate <0,0,5>

Rotating a vector around an axis can be done with the rotation formula. The
best explanation you'll find of this will probably be in a trigonometry
book, but what it comes down to is:

(to rotate in 2 dimensions)
x' = x cos(theta) - y sin(theta)
y' = y cos(theta) + x sin(theta)

So for example

rotate <3,0,0>

can be mimicked by

#declare spherepos =
    <spherepos.x,
     spherepos.y*cos(radians(3)) - spherepos.z*sin(radians(3)),
     spherepos.z*cos(radians(3)) + spherepos.y*sin(radians(3))>;

This is untested code so it's very possible I got something wrong. However,
let me give you the better solution for use in POV-Ray:

#include "transforms.inc"

#declare spheretransform = transform {
translate <1,2,3>
rotate <4,5,6>
scale <7,8,9>
rotate <10,11,12>
// etc
}

#declare spherepos = <0,0,0>;
sphere {spherepos, 1
transform spheretransform
}
#declare spherepos = vtransform(spherepos, spheretransform)

And spherepos will be at the new center of your sphere.

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


Post a reply to this message

From: Tim Nikias
Subject: Re: determining location of an object that has been transformed and rotated
Date: 15 Sep 2004 17:15:38
Message: <4148b0fa$1@news.povray.org>
Though Slime's answer is very thorough, he missed another nice feature...

If you want to rotate a position, simply apply the rotation to a vector
using vrotate, like this:

#declare NewPosition = vrotate(OldPosition,RotationVector);

And voila! The position gets rotated! :-)

Regards,
Tim

-- 
"Tim Nikias v2.0"
Homepage: <http://www.nolights.de>


Post a reply to this message

From: Mike Williams
Subject: Re: determining location of an object that has been transformed and rotated
Date: 15 Sep 2004 18:30:21
Message: <G7bShDAbHMSBFwNd@econym.demon.co.uk>
Wasn't it Jeremiah Isaacs who wrote:
>Where is the center of the sphere after the transformations in <x,y,z>
>coordinates?

Since it's spherically symmetrical, you can always ask POV where its
centre is. 

#declare MySphere = 
sphere {0,1
  translate z*10
  rotate SomeVector
} 

#declare Centre = (max_extent(MySphere) + min_extent(MySphere))/2;

-- 
Mike Williams
Gentleman of Leisure


Post a reply to this message

From: Jeremiah Isaacs
Subject: Re: determining location of an object that has been transformed and rotated
Date: 16 Sep 2004 16:15:01
Message: <web.4149f391efcc6b86758848d0@news.povray.org>
Thanks for the pointers on this.  These answers get everything I need to do
and more.

Thanks again - Jeremiah


Post a reply to this message

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