|
|
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
|
|
|
|
> 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
|
|