问题
Process of scaling x,y coordinates of one rectangle to other rectangle coordinates is pretty simple as better explained at this link
http://www.icoachmath.com/math_dictionary/scale_factor.html
if we have two rectangle one is having Maxwidth: 2000 and Maxheight: 1000
and second rectangle of size MaxWidth : 4000 and MaxHeight = 2000
so scale factor for converting coordinate of rect1 to rect2 would be
for x in rect2 : (x in rect1) * (MaxWidth of Rect2/ MaxWidht of Rect1) for y in rect2 : (y in rect1) * (MaxHeight of Rect2/ MaxHeight of Rect1)
but what should be scale factor when
for one rectangle center is origin(X,Y - 0,0) would be at the center and there would be negative values for x and y as well if you go left from center then x would be in negative and in right side it would be positive same for Y, if you go up then y would be positive but if you go to bottom, thenY Would be negative, so extents of this rectangle tends to ( -MaxWidth to +MaxWidth, -MaxHeight to +MaxHeight)
Now we have second rectangle which is having center at most left and top most position (most left and top most-0,0) and as we have to travel in right direction along x axis and down along y axis, So there would be always positive values for x and y.
So, how to calculate scale factor for converting coordiantes of rectangle which has the origin at center of rectanlge(MaxWidth/2,MaxHeight/2) to the rectanlge which has origin at most left and top most position
回答1:
Let's first rectangle has coordinates of two (diagonal opposite) corners:
(X0_Old, Y0_Old) and (X1_Old, Y1_Old)
and the second one -
(X0_New, Y0_New) and (X1_New, Y1_New)
then coordinate transformation will look like
for every point:
X_New = X0_New + (X_Old - X0_Old) * X_Coeff
where
X_Coeff = (X1_New - X0_New) / (X1_Old - X0_Old)
(and tha same for Y-coordinates)
来源:https://stackoverflow.com/questions/20536770/calculate-scaling-factor-for-converting-point1-x-y-coordinates-of-one-rectangl