Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scale 2D coordinates and keep their relative euclidean distances intact?

I have a set of points like: pointA(3302.34,9392.32), pointB(34322.32,11102.03), etc.

I need to scale these so each x- and y-coordinate is in the range (0.0 - 1.0). I tried doing this by first finding the largest x value in the data set (maximum_x_value), and the largest y value in the set (minimum_y_value). I then did the following:

pointA.x = (pointA.x - minimum_x_value) / (maximum_x_value - minimum_x_value)
pointA.y = (pointA.y - minimum_y_value) / (maximum_y_value - minimum_y_value)

This changes the relative distances(?), and therefore makes the data useless for my purposes. Is there a way to scale these coordinates while keeping their relative distances the intact?

like image 310
eiaxlid Avatar asked Mar 15 '10 19:03

eiaxlid


1 Answers

You need to scale the x values and the y values by the same amount! I would suggest scaling by the larger of the two ranges (either x or y). In pseudocode, you'd have something like

scale = max(maximum_x_value - minimum_x_value,
            maximum_y_value - minimum_y_value)

Then all the distances between points will be scaled by scale, which is what I presume you're asking for, so if point p_1 was twice as far from point p_2 as from p_3 before rescaling, it will be twice as far after rescaling as well. You should be able to prove this to yourself pretty easily using the Pythagorean theorem.

like image 166
Pillsy Avatar answered Nov 15 '22 08:11

Pillsy