Generate a new random point from a point based on some conditions

88 Views Asked by At

Imagine I have a point $O$ whose positions are known. I have another point $A$ which has a known position and a known heading. I want to generate a new point $B$ from $A$ where the distance between two points is $5$ and the heading is chosen randomly in a range of (heading of point $A$ - $0.4$, heading of point $A$ + $0.4$) and the position is calculated from the distance and the new random chosen heading. Now here are my questions:

1- How to make sure that this random heading is chosen in a way that we are getting farther and farther from $O$? Meaning that if there is another point $C$ which is generated from $B$, this point $C$ needs to get farther and farther from $O$.

2- The same as the first question but this time we are getting closer and closer to $O$.

I am not looking for a solution where we generate a point and we check to see if the distance is increasing (or decreasing for 2) and if not we regenerate. I am looking for a solution that does this by calculation.

Thank you

1

There are 1 best solutions below

5
On

Your vector $\vec{A}$ is a distance $|\vec{A}| = A$ from $O$.

There will be a heading change $\theta$ such that $|\vec{A} + \vec{B}| = A$.

In other words, you have a circle of radius $A$ centered at the origin. Change the heading of $\vec{A}$ by $\theta$ to get the heading of $\vec{B}$. The value of $\theta$ is chosen such that the vector sum of $\vec{A}$ and $\vec{B}$ lands on the original circle. This means that you're at the same distance from $O$ that you were before.

You can calculate $\theta$ and then assign the full range of your random variable ($\pm 1$ say) to $\pm \theta$. This will ensure you never get closer to $O$.

To ensure you never get farther from $O$, it's the same argument, but use the range $\pi - \theta$ to $\pi + \theta$ instead.