0

My question is if there is something built into any of the python libraries that would allow me to generate a random cluster of 3D points (x,y,z) around a given x,y,z point?

I can't seem to find anything similar to this but I am new to python so I'm not sure if its blindingly obvious or I have to try do it manually by using random numbers within a certain range of the given point

Ben
  • 2,518
  • 4
  • 18
  • 31

1 Answers1

1

Just use the random library;

This will give you poitns uniformly spaced aroudn the original point.

import random
source = [x,y,z]

deviationFromPoint = 10

for _ in range(numberOfAdditionalPoints):
  newCoords = [source[i] + random.random() * deviationFromPoint for i in range(3)]
  newPoint = Point(newCoords) # Or whatever constructor you have for your points.

If you want a different distribution, jsut use a different distribution, look in the documentation of random

will
  • 10,260
  • 6
  • 46
  • 69
  • Doesn't really answer my question in a sense because I was asking did something exist to do this but you did solve my problem so thanks! I will accept when I can – Ben Nov 12 '14 at 19:48
  • Well, are you using a library to deal with the 3D points? or have you just created your own class? – will Nov 12 '14 at 21:07
  • I think this answer is close but the set of points would be confined in a cube not a sphere – taari May 21 '21 at 12:42
  • @SawanVaidya that wasn't specified in the question, but if that's a requirement, then you could run a check that the point is farther away than the specified deviation, you throw it away and try again. – will May 21 '21 at 21:17