|
|
// Conversion from cubic_spline to bezier_spline
camera{
orthographic
location <0,30,0>
look_at 0
}
background { color rgb 1}
#local cubic_point=array[7]{
<3,8>
<-7,9>
<-5,-2>
<-10,-14>
<8,-14>
<5,-6>
<11,0>
}
#local n=dimension_size(cubic_point,1);
#local cubic_sp=spline{
cubic_spline
-1,cubic_point[n-1]
#local i=0;
#while(i<n)
i, cubic_point[i]
#local i=i+1;
#end
i, cubic_point[0]
i+1,cubic_point[1]
}
#local cubic_prism=prism {
linear_sweep
cubic_spline
-3,
3,
n+3,
cubic_point[n-1]
#local i=0;
#while(i<n)
cubic_point[i]
#local i=i+1;
#end
cubic_point[0]
cubic_point[1]
};
// convert cubic spline => bezier spline
//
// A and D are end points on the cubic segment,
// S1 and S2 are middle points on the cubic segment:
#local bezier_point=array[n];
#local i=0;
#while(i<n)
#local A=cubic_sp(i);
#local S1=cubic_sp(i+1/3);
#local S2=cubic_sp(i+2/3);
#local D=cubic_sp(i+1);
#local B=3*(S1-S2/2)+(D-2.5*A)/3;
#local C=3*(S2-S1/2)+(A-2.5*D)/3;
#local bezier_point[i]=array[4]{A,B,C,D};
#local i=i+1;
#end
#local bezier_prism=prism {
linear_sweep
bezier_spline
-3,
3,
n*4,
#local i=0;
#while(i<n)
bezier_point[i][0]
bezier_point[i][1]
bezier_point[i][2]
bezier_point[i][3]
#local i=i+1;
#end
};
#object{cubic_prism
scale 0.5
rotate z*180
translate x*-7
}
#object{bezier_prism
scale 0.5
translate x*7
}
Post a reply to this message
|
|