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