Summary

What is a sphere_sweep?

Demo-file: Demo1.pov

Sphere_sweeps are "curved objects created by translating a sphere along a certain path".

As shown below, there are three kinds of sphere_sweeps: Sphere_sweeps using a linear spline, a cubic spline or a b spline. To show the difference between these different forms, the points defining the sphere_sweeps have been marked by yellow spheres in the examples below, while the sphere_sweeps are marked in blue colour. While the linear and cubic splines result in sphere_sweeps containing exactly the positions used to define them, this is not the case when using b splines. Note in addition that in the cubic and b spline the outer positions are not included in the Sphere_Sweep. In general, this tutorial will focus on cubic splines.

Sphere_sweep, linea spline

Sphere_sweep, cubic spline

Sphere_sweep, b spline

In their simplest form, sphere_sweeps are defined by something like the following code (here the code for the cubic spline sphere_sweep shown above is given):

sphere_sweep {
cubic_spline // cubic curve
7, // number of specified sphere positions

//The positions defining the sphere_sweep:

<0, 2, 0>, 0.2 // position, radius
<2, 3, 0>, 0.2
<4, 1, 0>, 0.2
<6, 2.5, 0>, 0.2
<8, 2, 0>, 0.2
<10, 1, 0>, 0.2
<12, 3, 0>, 0.2
pigment { color rgb <0,0,1> }
}

A macro extracting position data for a Sphere_Sweep from an array

The sphere_sweep positions are not necessarily defined within the sphere_sweep; they can be derived from an array. Although this may appear complicated, there are some advantages of this approach: Above all, by separating the definition of the sphere's positions from the drawing of the actual sweep, the Pov-Ray script gains a clearer structure. This facilitates to apply more complex procedures for the calculation of these positions. In addition, it allows to reuse the positions stored in the array for the drawing of several, connected objects , as, e.g., a sphere_sweep and the corresponding spheres. The positions can be extracted from the array using a loop within the sphere_sweep. Such a sphere_sweep extracting its sphere's position from an array has been defined in the form of a macro below. There are many ways to improve this macro, e.g., by including the possibility to define a variable radius or a texture for the sphere_sweep. For this demonstration, however, we keep it as simple as possible.

#macro DrawSphereSweep (ArrayName, Radius, Number)
//This macro extracts the positions for a sphere_sweep from a given array.
//The name of the array, the radius of the sphere_sweep and the number of positions are the parameters for the macro.

//First the sphere_sweep is initiated.

sphere_sweep {
cubic_spline
Number,

//Then a loop is defined which extracts the positions from the array.

#declare ticker = 0;
#while (ticker < Number)
#declare P1 = ArrayName [ticker];
P1, Radius // position, radius
#declare ticker = ticker + 1;
#end

//Finally the sphere_sweep is finished.

pigment { color rgb <0,0,1> }
}
#end

Invoking this macro just takes the following line, where "Positions" refers to the name of the array, "0.2" to the Radius of the sphere_sweep and "Sum" to the number of positions stored in the array.

DrawSphereSweep (Positions, 0.2, Sum)

Now that we have separated the task of drawing a sphere_sweep from the task of defining the points for this sweep, we can concentrate on how to define those points. In the following chapters will present a number of possibilities. In the first approach, we will let the sphere_sweep walk by chance through a cloud of predefined positions. This way it is possible to obtain apparently random sphere_sweeps in a confined volume.

Summary