POV-Ray : Newsgroups : povray.general : please assist with function Server Time
5 Nov 2024 05:24:39 EST (-0500)
  please assist with function (Message 1 to 9 of 9)  
From: alphaQuad
Subject: please assist with function
Date: 1 Oct 2007 14:30:00
Message: <web.47013be548a27bd210a721da0@news.povray.org>
I am too new to grasp the function writing concept in POV.
the first step to matrix control is axis_rotation
#declare a=1.0;
#declare b=0.0;
#declare c=0.0;
#declare d=0.0;
#declare e=1.0;
#declare f=0.0;
#declare g=0.0;
#declare h=0.0;
#declare i=1.0;

#declare X=0.0;
#declare Y=0.0;
#declare Z=0.0;

#declare A=<a,b,c>;
#declare B=<d,e,f>;
#declare C=<g,h,i>;

#declare axis_rotation = function(r, z, y) {
// y * z * r //this only to see if pov accepts defined funtion parameters.
// it does.
// how to parse or tokenize a vector?

// C code is:
// r is radians (r,axis[3],point[3])

 /*
 double mag, s, c;
 double x, y, z, xx, yy, zz, xy, yz, zx, xs, ys, zs, one_c;
 s = sin(r);
 c = cos(r);
 mag = VLEN(axis);
     // prevent divide by 0 error and normalize axis
 if (mag == 0.0) mag = 1.0;
 x = axis[0] / mag;
 y = axis[1] / mag;
 z = axis[2] / mag;

 xx = x * x;
 yy = y * y;
 zz = z * z;
 xy = x * y;
 yz = y * z;
 zx = z * x;
 xs = x * s;
 ys = y * s;
 zs = z * s;
 one_c = 1.0 - c;

 x = point[0] * ((one_c * xx) + c);
 y = point[0] * ((one_c * xy) - zs);
 z = point[0] * ((one_c * zx) + ys);

 x += point[1] * ((one_c * xy) + zs);
 y += point[1] * ((one_c * yy) + c);
 z += point[1] * ((one_c * yz) - xs);

 x += point[2] * ((one_c * zx) - ys);
 y += point[2] * ((one_c * yz) + xs);
 z += point[2] * ((one_c * zz) + c);

 point[0] = x;
 point[1] = y;
 point[2] = z;
 */

//and usage should be: vector = axis_rotation(r,A,B)

}


Post a reply to this message

From: Nicolas Alvarez
Subject: Re: please assist with function
Date: 1 Oct 2007 14:37:19
Message: <47013e5f$1@news.povray.org>

> I am too new to grasp the function writing concept in POV.
> the first step to matrix control is axis_rotation

As far as I know, a function cannot return a vector. Maybe you're 
actually needing a #macro, not a function.


Post a reply to this message

From: alphaQuad
Subject: Re: please assist with function
Date: 1 Oct 2007 16:15:01
Message: <web.470154bbfdc645c010a721da0@news.povray.org>
Nicolas Alvarez <nic### [at] gmailisthebestcom> wrote:

> As far as I know, a function cannot return a vector. Maybe you're
> actually needing a #macro, not a function.


Right now you may only declare vector functions using one of the special
function types. Supported types are transform and spline functions. For
example:

#declare foo = function {
   transform {
     rotate <90, 0, 0>
     scale 4
   }
 }

 #declare myvector = foo(4, 3, 7);

 #declare foo2 = function {
   spline {
     linear_spline
     0.0, <0,0,0>
     0.5, <1,0,0>
     1.0, <0,0,0>
   }
 }
so without transform or spline it would be use of global floats only?
#declare axis_rotation = function(r, a,b,c,d,e,f) {?
} and one would still need to parse a vector at some point.



3.2.1.6  User-Defined Functions
Some objects allow you to specify functions that will be evaluated while
rendering to determine the surface of these objects. In this respect
functions are quite different to macros, [(macros?) assumed] which are
evaluated at parse time but do not otherwise affect rendering. Additionally
you may call these functions anywhere a Float Function is allowed, even
during parsing. The syntax is identical to Float Expressions, however, only
float functions that apply to float values may be used. Excluded are for
example strlen or vlength. You find a full list of supported float
functions in the syntax definition below.


not very clear at best.


Post a reply to this message

From: Tim Attwood
Subject: Re: please assist with function
Date: 1 Oct 2007 17:16:15
Message: <4701639f$1@news.povray.org>
This is a built in vector function vaxis_rotate in POV,
though the parameter order is different.

#declare A = <1,0,0>;
#declare B = <0,1,0>;
#declare M = vaxis_rotate(A,B,<0,90,0>);


Post a reply to this message

From: alphaQuad
Subject: Re: please assist with function
Date: 2 Oct 2007 02:50:00
Message: <web.4701e8bcfdc645c063d48a7c0@news.povray.org>
"Tim Attwood" <tim### [at] comcastnet> wrote:
> This is a built in vector function vaxis_rotate in POV,
> though the parameter order is different.
>
> #declare A = <1,0,0>;
> #declare B = <0,1,0>;
> #declare M = vaxis_rotate(A,B,<0,90,0>);

many thanks Tim!

the exercise was to take the ballroll anim from helpfile and roll it in a
circle
to test my ability to use pov.


#include "colors.inc"
#include "transforms.inc"

#declare A=<1.0,0.0,0.0>;
#declare B=<0.0,1.0,0.0>;
#declare C=<0.0,0.0,1.0>;

#declare rolls = 2.15;
/*
dist to travel / circumference of the sphere
aas-sin(pi/2,deg2rad(30),4.3) = 2.15
((2.15*2*pi) / (sphere_radius*2*pi)) rolls = 2.15 as long as sphere_radius=1
aas-sin {
  ; AAS solve opposing side of angle2 ($2)
  return sin($2) * ($3 / sin($1))
}*/

#declare Vector_Arrow=
 union{
   cylinder{<0,0,0>,2.5*z,.15}
   cone{2.5*z,.3,3*z,0}
 }

#declare objB=object{
  Vector_Arrow
  rotate <-30,0,0>
  rotate 360*clock*y
  pigment{Green}
}
#declare my = vaxis_rotate(vaxis_rotate(y,A,-30),B,360*clock);
#declare mz = vaxis_rotate(vaxis_rotate(z,A,-30),B,360*clock);
#declare mx = vnormalize(vcross(mz,my));
// #debug str(mx) need to check here if mx is positive. HOW? need to echo
this vector somehow
// or print to render window for which example in vect2.pov
#declare A_point = vrotate(vaxis_rotate(z,A,-30),360*clock*y)*4.1;
object{
  objB
}

sphere {
    <0, 0, 0>, 1
    pigment {
      gradient x
      color_map {
        [0.0 Blue  ]
        [0.5 Blue  ]
        [0.5 White ]
        [1.0 White ]
      }
      scale .25
      rotate <0,0,90>
    }
    Shear_Trans(mx,my,mz)
    Axis_Rotate_Trans(mz,-360* rolls *clock)

    translate A_point
}

camera {
    location <0, 3, -20>
    look_at <0, 0, 0>
    rotate <5,0,0>
    angle 25
}
light_source { <20, 20, -20> color White*1.6 }
plane {
    y, 1
    pigment { checker color White color Black }
}


posted to animations:
web.4701e81c27717bd263d48a7c0@news.povray.org


Post a reply to this message

From: alphaQuad
Subject: Re: please assist with function
Date: 2 Oct 2007 03:05:00
Message: <web.4701ec95fdc645c063d48a7c0@news.povray.org>
"alphaQuad" <alp### [at] earthlinknet> wrote:

> #declare A_point = vrotate(vaxis_rotate(z,A,-30),360*clock*y)*4.1;

4.1 was a typo.

4.1 == 4.3 as used for triangulation to num rolls, making little difference


Post a reply to this message

From: alphaQuad
Subject: Re: please assist with function
Date: 2 Oct 2007 03:25:00
Message: <web.4701f14efdc645c063d48a7c0@news.povray.org>
"alphaQuad" <alp### [at] earthlinknet> wrote:

> aas-sin(pi/2,deg2rad(30),4.3) = 2.15


and I got schitzo on the angle. elevation was 30 making angle 90-30.

aas-sin(pi/2,deg2rad(60),4.3) = 3.7239


Post a reply to this message

From: alphaQuad
Subject: Re: please assist with function
Date: 2 Oct 2007 13:20:01
Message: <web.47027ca3fdc645c07592d6e00@news.povray.org>
rolls = 4 for even numrolls, final:

web.4701fac16849f39cb23aa5d0@news.povray.org


Post a reply to this message

From: alphaQuad
Subject: Re: please assist with function
Date: 2 Oct 2007 13:35:01
Message: <web.470280c1fdc645c07592d6e00@news.povray.org>
for anyone reading this


the answers to all questions about vector parsing and matrix control
were given in transforms.inc


Post a reply to this message

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