0

I am trying to implement the algorithm provided in this link to generate n-randomly located points in a convex polygon using python. I have been able to complete steps 1 and 3 successfully, however don't quite understand how to complete step 2. Step 2 involves first:

  • finding the fraction of the total area that each triangle takes up, and store that in a list.
  • generating a random double number from 0 - 1

Using these two ingredients, the user states the following, and I quote:

subtract each value in the list until the next subtraction would make it negative

I find the above statement highly ambiguous. I understand that conceptually the numbers in the list represent some kind of likelihood for that item in the list to get picked, but I don't understand how to do the above, what needs to be done, or why it means that the weighting of triangle area is taken into consideration.

Could somebody please elaborate?

Thanks

EDIT

I also found this blog post which contains additional information, though I'm not quite convinced yet. Perhaps this has already been implemented somewhere?

user32882
  • 5,094
  • 5
  • 43
  • 82

1 Answers1

0

It looks like numpy already provides this functionality in numpy.random.choice. This answer provides more information. If the areas are contained in a list and normalized, then the list may serve as the probability distribution for the choice method.

user32882
  • 5,094
  • 5
  • 43
  • 82