**R5** (proper use of Radians)

Oh, now I know what the problem with the “failing” Radians was; The function returning the resulting degree didn’t also convert the returned value to Radians, but now it does (so this R5 will be the final version which works correctly):

```
/// <summary>
/// Returns the rotation (in radians) of the smallest volume. The parallel loop
/// performs m_rotations rotations of 1º each (90 rotations is default)
/// </summary>
```

```
private double GetRotationAtMinimumVolume(GeometryBase geo, Plane start_plane, Vector3d rotation_axis)
{
var rotated_volumes = new double[m_rotations];
// Let the .NET platform take care of spreading out the for-loop iterations on different threads.
// To avoid data races we use local block variables inside the for-loop, and results are put into
// array slots, each result into its own index in the array, which prevents "collisions" (meaning,
// different threads overwriting each others values).
System.Threading.Tasks.Parallel.For(0, m_rotations, i =>
{
// make new rotation of the original plane on each try
var new_plane = start_plane;
new_plane.Rotate(i * TO_RADIANS, rotation_axis);
// Since each thread works with different indexes (i), and when done, assigning
// each result value into "its own array index", then no conflict can occur be-
// tween threads so that any one thread would overwrite the result produced by
// another thread, and therefore no data-races will occur. This is a red-neck
// approach which ALWAYS works if the size of the array can be known in advance
rotated_volumes[i] = geo.GetBoundingBox(new_plane).Volume;
});
// now find that index (degree of rotation) at which we had the smallest BoundingBox
var rotation = IndexOfMinimumVolume(ref rotated_volumes);
return rotation * TO_RADIANS; // Edit: Conversion should be placed here. Angle in Radians
}
```

```
/// <summary> Returns the index of the smallest volume recorded in the
/// array </summary>
/// <param name="recorded_volumes"></param>
/// <returns>Returns the index of the smalles volume, which also is
/// equal to the degree at which this volume was achieved.</returns>
private double IndexOfMinimumVolume(ref double[] recorded_volumes)
{
var min_index = -1;
var min_value = Double.MaxValue;
for (var i = 0; i < recorded_volumes.Length; i++)
{
if (recorded_volumes[i] < min_value)
{
min_index = i;
min_value = recorded_volumes[i];
}
}
return min_index; // Index is the same as the degree
}
```

minimalboundingbox-py2csharp_R5.gh (614.6 KB)

// Rolf