0

Suppose we have some predefined positions statements in a 2d or 3d space (e.g. generated by a robot arm with the axis/joints x, y, z, a, b). How do we get any position statement (same format x, y, z, a, b) in between these points in Python (SciPy, NumPy, MatPlotLab, etc...)?

E.g. "What is the position statement for x = -2.5 and y = 152.8"

For better understanding, I have attached a small illustration of my problem.

any point in an n-dimensional space

Peter O.
  • 32,158
  • 14
  • 82
  • 96

1 Answers1

1

Essentially, for your problem:

  1. Calculate a bounding box that fits the given points.
  2. Generate a random point in the bounding box.
  3. If the random point is not in the convex hull of the given points, go to step 1.

For two-dimensional cases, if you know all the shapes you care about are convex, then this is relatively trivial: divide the shape into triangles, choose one of them at random based on their area, and generate a random point in that triangle. But for higher dimensions, this is far from trivial. In fact, the convex hull is likely to be much smaller than the bounding box with higher dimensions, so many points are likely to be rejected. And computing the convex hull itself may be complicated. This question's answers have some ideas on how to find if a point is inside a convex hull.

If you can accept approximations, you can also precalculate a number of points that are in the convex hull, then, each time you need a random point:

  • Choose one of the precalculated points at random.
  • Calculate a random point that's "close" to the chosen point (e.g., a point shifted by a normally-distributed distance in each dimension).
  • Clamp the random point by the bounding box.

This has the disadvantage that the random points will be as dense as the precalculated points, and not necessarily uniformly distributed.

Peter O.
  • 32,158
  • 14
  • 82
  • 96
  • Great Peter! Good approaches. Ok, let´s assume we have this convex hull (points specified by x,y,z coordinates and rotation angle a) from scipy.spatial import ConvexHull points = [[11.5, 152.5, 435.5, 68.4], [11.8, 158.3, 432.0, 72.3], [12.1, 164.1, 428.5, 76.2], [-40.5, 153.4, 433.6, 67.8], [-41.4, 156.9, 431.1, 71.1], [-42.3, 160.3, 428.6, 74.4]] hull = ConvexHull(points) How do I get specific or random points out of the box now? E.g. Point with x =5 and y = 159 – MonaLisa May 02 '20 at 07:40