Reputation: 25096
I have a number of points P of the form (x, y)
where x,y
are real numbers. I want to translate and scale all these points within a bounding box (rectangle) which begins at the point (0,0)
(top left) and extends to the point (1000, 1000)
(bottom right).
Why is it that the following algorithm does not produce points in that bounding box?
for Point p in P:
max = greatest(p.x, p.y, max)
scale = 1000 / max
for Point p in P:
p.x = (p.x - 500) * scale + 500
p.y = (p.y - 500) * scale + 500
I fear that this won't work when p.x
or p.y
is a negative number.
I would also like to maintain the "shape" of the points.
Upvotes: 0
Views: 1257
Reputation: 11883
Upvotes: 2