I’ve figured out this algorithm on my own, but I’m sure others also use something like this.
Have a look at this: