POV-Ray : Newsgroups : povray.advanced-users : Parametrics and isosurfaces : Re: Parametrics and isosurfaces Server Time
3 May 2024 16:50:47 EDT (-0400)
  Re: Parametrics and isosurfaces  
From: Bald Eagle
Date: 6 Aug 2016 15:40:00
Message: <web.57a63bf45c93b6e65e7df57c0@news.povray.org>
So, here's an example I'm currently grappling with.

I'd like to use a parametric to make a spherical harmonic following the MatLab
code here:
http://148.204.81.206/matlab/examples/spherical-surface-harmonic.html

For the time being, I'm assuming Legendre (degree, ....) and Ymn (order+1, ...)
are P6 and P2 which are the the polynomial equations here:

http://mathworld.wolfram.com/LegendrePolynomial.html

I populate an array with the results of these polynomials across 0 to pi or 0 to
2*pi.   I now want to use a RHO value to vary the radius as POV-Ray's parametric
evaluates the spherical coordinates across Theta and Phi (u and v).

r = rho.*sin(theta);
x = r.*cos(phi);    % spherical coordinate equations
y = r.*sin(phi);
z = rho.*cos(theta);


I'm trying to calculate a rho or an r value that smoothly varies with u.
As you can see below, I figured that defining a spline based on the polynomial
evaluations was a logical way to do this, but the parser complained when I tried
to use RhoSpline(u) in my functions, and still complains when I try to use a
user-defined function that returns a spline value.
"expected 'operand', but spline identifier found instead"

Maybe this is an inherent limitation of the parametric, maybe it's my continuing
struggle with using functions, or maybe it's a legit example of needing a RHO
term.

//##########################################################################

#version 3.7;
global_settings {assumed_gamma 1.0}
#include "colors.inc"
#include "textures.inc"
#include "shapes3.inc"

camera { location <0, 5, -20>
  look_at <0, 0, 0>}

light_source {<40, 30, -20> White}

background {Black}

#declare Degree = 6;
#declare Order = 1;
#declare Delta = pi/40;


// Legendre polynomials
#declare P_0 = function (T) {1};
#declare P_1 = function (T) {T};
#declare P_2 = function (T) {1/2 * (  3 * pow (T,2) -   1) };
#declare P_3 = function (T) {1/2 * (  5 * pow (T,3) -   3*T) };
#declare P_4 = function (T) {1/8 * ( 35 * pow (T,4) -  30 * pow(T,2) + 3) };
#declare P_5 = function (T) {1/8 * ( 63 * pow (T,5) -  70 * pow(T,3) + 15*T) };
#declare P_6 = function (T) {1/16* (231 * pow (T,6) - 315 * pow(T,4) + 105 *
pow(T,2) - 5) };

#declare RESULT = array [41][5];
#declare Element = 0;
#for (Theta, 0, pi-Delta, Delta)
#debug concat( " Theta = ", str(Theta, 3, 1),  " Element = ", str(Element, 3,
1), "\n")
 #declare RESULT [Element][0] = P_6 (cos(Theta));
 #declare RESULT [Element][1] = P_2 (cos(Theta));
 #declare Element = Element + 1;
#end // end for Theta

#declare Element = 0;
#declare Order = 0;
#for (Phi, 0, 2*pi-2*Delta, 2*Delta)
 // populate the
 #declare RESULT [Element][2] = RESULT [Element][0] * cos(Order*Phi);
 #declare RESULT [Element][3] = RESULT [Element][1] * cos(Order*Phi);
 #declare RESULT [Element][4] = max (abs(RESULT [Element][2]), abs(RESULT
[Element][3]));
 #declare Order = max (Order, RESULT [Element][4]);  // overall max
 #declare Element = Element + 1;
#end // end for Phi

#declare RhoSpline =
spline {
  cubic_spline
    -Delta, 0,  // Control point
 #for (S, 0, pi-Delta, Delta)
  S, RESULT [S/Delta][4]
 #end // end for S
     pi+Delta, 0  // Control point
    }

#declare R = function (T) {abs(RhoSpline(T))};

#declare W = 10; //contained_by box size

parametric {
 // RHO = (5+2*RESULT[u*pi][4]/Order)
 // r   = (5+2*RESULT[u*pi][4]/Order) * sin(u)
 // R() is function defined above
  function { (5+2*RhoSpline(u)/Order) * sin(u) * cos(v) }, // x-axis
  function { (5+2*R(u)/Order) * sin(u) * sin(v) }, // y-axis
  function { (5+2*R(u)/Order) * cos(u) }   // z-axis
  <0, 0>, <pi, 2*pi>         // <Umin, Vmin>, <Umax, VMax>  (Theta, Phi =
Altitude, Azimuth)

  //contained_by { sphere { 0,1 } } // texturing problem, use box instead to
see!
  contained_by { box { <-1,-1,-1>*W, <1,1,1>*W } }
  // max_gradient 2
  accuracy 0.005        // 0.001 default, lower slower but better
  precompute 15 x,y,z   // precompute [x,y,z] normally gives faster rendering
(<=20)
  scale 1
  texture {pigment {color White } }
  //translate<0,1,0>
}


Post a reply to this message

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