Calculate scaling factor for converting point1( x,y coordinates) of one rectangle to Point1( x,y) of a different rectangle

StackOverflow https://stackoverflow.com/questions/20536770

Question

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

No correct solution

OTHER TIPS

Let's the first rectangle has coordinates of two (diagonal opposite) corners:

(X0_Old, Y0_Old) and (X1_Old, Y1_Old)

and the second one coordinates are:

(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 the same for Y-coordinates)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top