0

I have two input variables, let's call them x and y, which are the inputs to a function. There is a condition for these two inputs: x+y must be equal to or less than 1. So, my input space would look like this:

Original input space

I have a python package that can select a random point in an input space (it does more but just to make it simple, let's say just select a random point), but it only accepts rectangular bounds for input space. So, I need an input space like:

desired input space

I wonder how I can select a point in the second input space and transform the selected point by a mathematical formula to the first input space (and vice versa, because I also need to update the python function about selecting the points.)

Do you know, what formulates the desired transformation? I also need to generalize this transformation to more input dimensions (x+y+z <= 1), so if you already know the generalised formula, that would be awesome to share.

  • 1
    There are bijective mappings between a triangle and a rectangle (see for example https://math.stackexchange.com/q/1212629/42969). But in order to get random points in a triangle (with uniform distribution) there are probably better methods. For example: create random points in the square $[0, 1] \times [0, 1]$, and repeat until the point is inside the triangle. – Martin R Dec 05 '22 at 15:20
  • @MartinR Random selection is just a simplification, not what actually my python package does. It's not random at all. but thanks for the comment and the link. – Arash Heidari Dec 05 '22 at 15:22
  • Why not choose a point in the unit square and then, if it is above the line $y = 1-x$, reflect it across that line? – Xander Henderson Dec 05 '22 at 15:35
  • @XanderHenderson Because it is not how the function works. Selecting a random point is just a simplification. It's not random at all. It's just an example. I need the transformation and not a way to select a random point in a triangle. – Arash Heidari Dec 05 '22 at 15:43
  • Then your question is unclear to me. As I understand your question, you are trying to uniformly select a point from a right triangle, but have an algorithm which can uniformly select a point from a square. The algorithm I gave you allows you to take a point from the unit square and map it into the triangle. This map hits every point in the triangle twice, with uniform density. How does this not do what you want it to do? – Xander Henderson Dec 05 '22 at 15:47
  • @XanderHenderson I didn't want to make it complicated in my question, but I want to use this: https://bitbucket.org/gramacylab/tricands/src/main/ – Arash Heidari Dec 05 '22 at 15:49
  • @XanderHenderson The problem with your suggested method is that it's not one-to-one. Yes. I can select a point on the other side of the line, but if I want to transform it back, then I don't know which side of the line the original point was. I want to transform and also be able to transform back. – Arash Heidari Dec 05 '22 at 15:52

0 Answers0