Summary

Targeted random sweeps

Demo-file: Demo6.pov

In this chapter, we will introduce a more targeted approach to create sphere_sweeps, which look more or less random. With the macro introduced here, it will be possible to connect two given points by a sphere_sweep. The variance of this sphere_sweep will be another parameter of the macro. This method will be used in later chapters, to created more targeted branching patterns than those shown before.

sphere_sweep, low variance sphere_sweep, high variance

For some of these branching patterns, it may be important to be able to find subpositions on these sphere_sweeps, positions situated between the points constituting the sphere_sweeps. I will introduce a macro which allows you to do so. (Creating the red labels in the picture below.)

sphere_sweep, subpositions

Let us start with defining a macro which will create an array for a sphere_sweep between two given positions. This macro takes as input parameters the start and end position of the sphere_sweep (P1 and P2), the number of positions defining the sphere_sweep, the variance of the sphere_sweep and the name for the array produced. This array should be initialized before invoking the macro.
In the first part of the macro the two outer points and the start and end point of the sphere_sweep are defined. The remaining intermediate positions are defined by regularly dividing the line between the start and end position and by adding a certain element of randomness (in all three dimensions). The size of this element of irregularity can be controlled by the parameter “Variance”.

#macro Sweep_Regular (P1, P2, Number, Variance, ArrayName)

//Definition of P1 and P2 and of the outer positions.
#declare ArrayName[0] = P1 + (1/Number*(P1-P2));
#declare ArrayName[1] = P1;
#declare ArrayName[Number-2] = P2;
#declare ArrayName[Number-1] = P2 + (1/Number*(P2-P1));

//Loop for defining the intermediate positions.
#local ticker = 2;
#while (ticker <Number-2)
#declare ArrayName [ticker] = P1 + ((ticker-1)/(Number-3) * (P2-P1)) + <:Variance *(rand(chance1) - 0.5), Variance *(rand(chance2) - 0.5), Variance *(rand(chance3) - 0.5)>;
#local ticker = ticker + 1;
#end
#end

Before invoking this macro "Sweep_Regular", three pseudo-random streams have to be initialized, as well as the array used in the macro. The macro then puts the data generated into this array ("Positions"), which can be used in the subsequent macro ("DrawSphereSweep", see previous chapters) for drawing the Sphere_Sweep.

#declare chance1 = seed (3);
#declare chance2 = seed (6);
#declare chance3 = seed (5);

#declare Sum = 7;
#declare Positions = array[Sum];

Sweep_Regular (<0, 2, 0>, <12, 4, 0>, Sum, 0.5, Positions) //Definition of Positions.

DrawSphereSweep (Positions, 0.2, Sum) //Drawing the Sphere-Sweep.

Before we come to more practical applications of the macros introduced above, I want to introduce another useful macro. This macro is able to find points within a Sphere_Sweep situated between the points defining this Sphere_Sweep. While such a task may appear to be trivial for the Sphere_Sweep with Variance = 0.5 shown above, it is not trivial for more irregular Sphere_Sweeps. In these cases a simple regular division of the distance between two sphere positions will only lead to positions situated nearby the Sphere_Sweep but not within the Sphere_Sweep. The macro introduced here starts with such positions and searches to find the closest distance to the nearby Sphere_Sweep. In a second step it tries to localize the final position of the point in question in the very center of the Sphere_Sweep. It would take too long to quote and explain the complete macro here. It can be found, however, in the respective demo-file.

#macro Subdivisions (InputArray, PositionNumber, DivisionNumber, SweepRadius, OutputArray) //This macro searches for
//Subdivisions of a Sphere_Sweep.

//InputArray refers to the array containing the original Positions for the Sphere_Sweep.
//PositionNumber refers to the number of these Positions actually defining the Sphere_Sweep
//(i.e. the number of positions stored in the array - 2).
//Smaller values for PositionNumber will result in the formation of Subdivisions for only a part of the sphere_sweep.
//DivisionNumber refers to the number of new points between two positions on the Sphere_Sweep.
//SweepRadius refers to the radius of the Sphere_Sweep. (Determines how exactly the new points are placed
//in the center of the Sweep.
//OutputArray refers to the name of the output-array. This array will contain the old positions as well as the newly defined positions.

Summary