|
|
Tor Olav Kristensen fixed one problem with my sinespline and then I saw
that what I really needed was a CosineSpline!
Here is a test scene, all fixed up!
Red dots: linear poitns
Yellow curve: #init_spline
Blue curve: Cosine spline
The yellow #init_spline gives the most smooth curve, but it's not too
proud to stay within the range of original points. The blue curve isn't
the smoothest or prettiest, but it behaves.
-------------------------------------
test scene
#version 3.1;
#include "colors.inc"
//by Greg M. Johnson and improved by Tor Olav Kristensen
#macro sinespline(xgive, ptArray)
#local jj = 0;
#local nextx = ptArray[jj].x;
#local Found = false;
#while (!Found & (jj < dimension_size(ptArray, 1) - 1))
#local lastx = nextx;
#local jj = jj+1;
#local nextx = ptArray[jj].x;
#local Found = ((xgive >= lastx) & (xgive < nextx) ? true : false);
#end // while
(Found ? ptArray[jj].y +
(ptArray[jj-1] - ptArray[jj]).y*
0.5*(
cos
(pi*
(xgive - lastx)/(nextx - lastx)
)+1
)
: 0)
#end // macro sinespline
#init_spline {"initspline",
< 0.000, -15.0 >,
< 0.250, -125.0 >,
< 0.450, -110.0 >,
< 0.500, -10.0 >,
< 0.750, -25.0 >,
< 1.000, -15.0 >
}
#declare pn =
array[6] {
< 0.000, -15.0 >,
< 0.250, -125.0 >,
< 0.450, -110.0 >,
< 0.500, -10.0 >,
< 0.750, -25.0 >,
< 1.000, -15.0 >
}
#declare Radius = 3;
#declare sc = <300, 1, -3>;
#declare Cnt = 0;
#while(Cnt < 1)
sphere {
<Cnt, sinespline(Cnt, pn), 1>*sc, Radius
pigment{ Blue }
finish{ ambient 1 }
}
#declare Cnt = Cnt + .002;
#end
#declare Cnt = 0;
#while(Cnt < 1)
sphere {
<Cnt, eval_spline ("initspline",Cnt), 4>*sc, Radius*0.5
pigment{ Yellow }
finish{ ambient 1 }
}
#declare Cnt = Cnt + .006;
#end
#declare Cnt = 0;
#while(Cnt < dimension_size(pn, 1))
sphere {
<pn[Cnt].x, pn[Cnt].y, 1>*sc, Radius*1.25
pigment{ Red }
finish{ ambient 1 }
}
#declare Cnt = Cnt + 1;
#end
camera {
location <130, -75, -300>
look_at <130, -75, 0.0>
}
Post a reply to this message
Attachments:
Download 'cosinespline.jpg' (16 KB)
Preview of image 'cosinespline.jpg'
|
|