POV-Ray : Newsgroups : povray.binaries.images : vrotate example from p.general : Re: vrotate example from p.general Server Time
29 Jul 2024 22:25:37 EDT (-0400)
  Re: vrotate example from p.general  
From: Bald Eagle
Date: 16 Aug 2013 19:15:01
Message: <web.520eb1e1286ea79673fc9ebb0@news.povray.org>
Er, that did nothing but confuse me.  Especially the sphere.
The perspective camera didn't help.



#include "colors.inc"

camera { orthographic
     location <-15, 0, -35>
     //up y
     //right x*(image_width/image_height)
     look_at 0
    }

light_source { <-15, 10, -30> rgb 1 }

background {color Blue*0.5}

// define variables
//#######################################################
#default { texture {pigment {White} finish {ambient 0.6}}}
#declare Translation_1 = 3;
#declare Translation_2 = 4;
#declare Translation_3 = -10;
#declare Diameter = 0.2;
#declare Length = 10;
#declare Coordinates_1 = vrotate (<Translation_1, Translation_2, Translation_3>,
<30, 0, 0>);
#declare Coordinates_2 = vrotate (<Translation_1, Translation_2, Translation_3>,
<30, 60, 0>);
#declare Coordinates_3 = vrotate (<Translation_1, Translation_2, Translation_3>,
<30, 60, 90>);


// define an obviously asymmetric object
//#######################################################
#declare obj = union{
cylinder { <0, 0, 0>, <0, 2, 0>, 0.125 }
sphere {<0, 2.125, 0>, 0.5}
cylinder { <0, 0, 0>, <2, 0, 0>, 0.125 }
box {<0, 0, 0>, <1, 1, 1> translate <1+0.5, -0.5, -0.5>}
cylinder { <0, 0, 0>, <0, 0, -2>, 0.125 }
cone {-z*2, 0.3, -z*2.25, 0 }
}
//#######################################################


/*
vrotate(A,B) Rotate A about origin by B.
Given the x,y,z coordinates of a point in space designated by the vector A
[<x1,y1,z1>],
rotate that point about the origin by an amount specified by the vector B
[<xr,yr,zr>].
Rotate it about the x-axis by an angle specified in degrees by the float value
B.x [xr].
Similarly B.y [yr] and B.z [zr] specify the amount to rotate in degrees about
the y-axis and z-axis.
The result [that vrotate returns] is a vector containing the new x,y,z
coordinates of the point [x2,y2,z2].

Description from POV-Ray Help, annotations in square brackets[ ].

*/



//     EXAMPLE 1 - GREEN AXES
union {
    cylinder { -Length*y, Length*y, Diameter texture {pigment {Green} finish
{ambient 0.6}} }
    cylinder { -Length*x, Length*x, Diameter texture {pigment {Green} finish
{ambient 0.6}} }
    cylinder { -Length*z, Length*z, Diameter texture {pigment {Green} finish
{ambient 0.6}} }


//################################################################################################
// THIS IS THE KEY CONCEPT - COMPARE TO AN ACTUAL ROTATION IN SECOND EXAMPLE
//################################################################################################

    object { obj
     translate vrotate(<Translation_1, Translation_2, Translation_3>, <30, 60,
90>)
     texture {pigment {Yellow} finish {ambient 0.6}}
     // TRANSLATE object at <x1, y1, z1> to where it would end up if rotated by
<30, 60, 90>
     }
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//################################################################################################


    object {obj texture {pigment {Green} finish {ambient 0.6}} translate
<Translation_1, Translation_2, Translation_3>}  // mark original position

    object {obj texture {pigment {White transmit 0.5} finish {ambient 0.6}}
translate Coordinates_1}
    torus {vlength(<0, Translation_2, Translation_3>), 0.2 rotate z*90 translate
x*Translation_1
    texture {pigment {White transmit 0.7 } finish {ambient 0.4}} no_shadow}

    object {obj texture {pigment {White transmit 0.5} finish {ambient 0.6}}
translate Coordinates_2}
    torus {vlength (<Coordinates_1.x, 0, Coordinates_1.z>), 0.2 translate
y*Coordinates_1.y
    texture {pigment {White transmit 0.7} finish {ambient 0.4}} no_shadow}

    //sphere {<Translation_1, Translation_2, Translation_3>, 0.5 rotate x*30
rotate y*60 rotate z*90}
    torus {vlength (<Coordinates_2.x, Coordinates_2.y, 0>), 0.2 rotate x*90
translate z*Coordinates_2.z
    texture {pigment {White transmit 0.7} finish {ambient 0.4}} no_shadow}

    cylinder { <Translation_1, Translation_2, Translation_3>, Coordinates_3,
Diameter
    texture {pigment {Blue} finish {ambient 0.6}} }
    //cone {x*(Translation_1-1), Diameter*3, x*Translation_1, 0 }

    translate -15.0*x
    }




//################################################################################################
//     EXAMPLE 2
//     RED AXES
union {
    cylinder { -Length*y, Length*y Diameter texture {pigment {Red} finish
{ambient 0.6}}}
    cylinder { -Length*x, Length*x Diameter texture {pigment {Red} finish
{ambient 0.6}}}
    cylinder { -Length*z, Length*z Diameter texture {pigment {Red} finish
{ambient 0.6}}}

//################################################################################################
//  HERE THE OBJECT IS ROTATED AROUND THE x, THEN y, THEN z AXES
//################################################################################################
    object { obj
      translate <Translation_1, Translation_2, Translation_3>
      rotate <30, 60, 90> }

//  NOTE THAT ALTHOUGH THE OBJECT WINDS UP AT THE SAME FINAL POSITION,
//   ITS ORIENTATION HAS CHANGED DUE THE ROTATIONS
//################################################################################################

        translate 10.0*x
        texture {pigment {Yellow} finish {ambient 0.6}}
    }

union{

    object {obj translate <Translation_1, Translation_2, Translation_3>
    texture {pigment {Green} finish {ambient 0.6}} }  // mark original position

    object {obj translate <Translation_1, Translation_2, Translation_3> rotate
x*30
    texture {pigment {White transmit 0.5 } finish {ambient 0.6}} no_shadow}
    torus {vlength(<0, Translation_2, Translation_3>), 0.2 rotate z*90 translate
x*Translation_1
    texture {pigment {White transmit 0.7 } finish {ambient 0.4}} no_shadow}

    object {obj translate <Translation_1, Translation_2, Translation_3> rotate
x*30 rotate y*60
    texture {pigment {White transmit 0.5 } finish {ambient 0.6}} no_shadow}
    torus {vlength (<Coordinates_1.x, 0, Coordinates_1.z>), 0.2 translate
y*Coordinates_1.y
    texture {pigment {White transmit 0.7 } finish {ambient 0.4}} no_shadow}

    //sphere {<Translation_1, Translation_2, Translation_3>, 0.5 rotate x*30
rotate y*60 rotate z*90}
    torus {vlength (<Coordinates_2.x, Coordinates_2.y, 0>), 0.2 rotate x*90
translate z*Coordinates_2.z
    texture {pigment {White transmit 0.7 } finish {ambient 0.4}} no_shadow}

    cylinder { <Translation_1, Translation_2, Translation_3>, Coordinates_3,
Diameter
    texture {pigment {Blue transmit 0.7} finish {ambient 0.6}} }
    //cone {x*(Translation_1-1), Diameter*3, x*Translation_1, 0 }

        translate x*10.0
}


Post a reply to this message


Attachments:
Download 'vrotate.png' (31 KB)

Preview of image 'vrotate.png'
vrotate.png


 

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