Spreading out points

Hi everyone, I need some help with the traveling salesman problem. The issue I am having is that the (x, y) points of each city are too close to each other. As such, I get the result in the image below. Is there a way I could “spread the points” while retaining the relative distance? I tried using scale, but it goes out of the window. Thanks!

1 Like

Welcome to the forums!

Are you saying you already tried using the scale() function? I think this should do the trick.
You can also try to multiply each point’s coordinates by a factor of x, which will preserve the original coordinates. Something like:

int x = 50;
int y = 65;

void draw(){
    point(x * 2, y * 2)
}

Either way, this is gonna “move” them away from (0,0), so you’ll want to look into translate() and shift them back into view.

2 Likes

When you get the points by random you can also increase the value in random

2 Likes

Got it. Thank you so much!!

1 Like