Trying to loop a list of two lines based on randomly generated points.
Within a rectangular boundary from (0,0,0) to (10,10,0) both lines should be longer than 12.
The shorter line being only 3.86 long, the loop obviously doesn’t work with the list.
Can anyone tell me what’s wrong with the code?
However with only one random line, i.e. without using a list, the loop, though not being very fast, works.
I tried a similar example using AutoCAD and VB.NET, where loop calculation seemed to be much faster.
Why is this?
= = = = =
Loop while code for list
= = = = =
geometry = [Imperative]
{
// use range expressions to generate collection of numbers
nums1x = {Math.Random (0, 10), Math.Random (0, 10)};
nums1y = {Math.Random (0, 10), Math.Random (0, 10)};
nums2x = {Math.Random (0, 10), Math.Random (0, 10)};
nums2y = {Math.Random (0, 10), Math.Random (0, 10)};
// use the collections of numbers to generate collections of points
points1 = Point.ByCoordinates(nums1x, nums1y, 0);
points2 = Point.ByCoordinates(nums2x, nums2y, 0);
// use the collections of points to generate a collection of lines
lines = Line.ByStartPointEndPoint(points1, points2);
// generate a list of line lengths
list1 = lines.Length;
// generate the minimum length within the list
list1min = List.MinimumItem(list1);
// loop while length is smaller than …
while (list1min < 12)
{
nums1x = {Math.Random (0, 10), Math.Random (0, 10)};
nums1y = {Math.Random (0, 10), Math.Random (0, 10)};
nums2x = {Math.Random (0, 10), Math.Random (0, 10)};
nums2y = {Math.Random (0, 10), Math.Random (0, 10)};
points1 = Point.ByCoordinates(nums1x, nums1y, 0);
points2 = Point.ByCoordinates(nums2x, nums2y, 0);
lines = Line.ByStartPointEndPoint(points1, points2);
list1 = lines.Length;
list1min = List.MinimumItem(list1);
}
return = lines;
};