计算将一个矩形的point1(x,y坐标)转换为不同矩形的Point1(x,y)的缩放因子 [英] Calculate scaling factor for converting point1( x,y coordinates) of one rectangle to Point1( x,y) of a different rectangle

查看:396
本文介绍了计算将一个矩形的point1(x,y坐标)转换为不同矩形的Point1(x,y)的缩放因子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将一个矩形的x,y坐标缩放到其他矩形坐标的过程非常简单,如在此链接中更好地解释



http://www.icoachmath.com/math_dictionary/scale_factor.html



<如果我们有两个矩形,则有Maxwidth:2000和Maxheight:1000



,第二个矩形的大小MaxWidth:4000和MaxHeight = 2000



所以用于将rect1的坐标转换为rect2的缩放因子为



为rect2中的x:rect1中的x Rect1的Rect2 / MaxWidht)
在rect2中的y:(rect1中的y)*(Rect2的MaxHeight / Rect1的MaxHeight)



因此当一个矩形中心的



是原点(X,Y - 0,0)将位于中心,并且x和y也将为负值你从中心向左移动,然后x将是负的,在右边,它将是正的相同的Y,如果你向上,那么y将是积极的,但如果你去底部,那么Y将是负的,所以这个矩形的范围趋向to(
-MaxWidth to + MaxWidth,-MaxHeight to + MaxHeight)



现在我们有第二个矩形,其中心位于最左边, b $ b(最左边和最上-0.0),因为我们必须沿着x轴向右移动,沿着y轴向下移动,所以x和y总是为正值。



因此,如何计算将原点在矩形中心(MaxWidth / 2,MaxHeight / 2)的矩形的坐标转换为原点最左边和最顶点的矩形的比例因子位置

解决方案

让我们先来看一个矩形的坐标是两个对角线:
X0_Old,Y0_Old)和(X1_Old,Y1_Old)
,第二个 -
(X0_New,Y0_New) c $ c>



那么坐标转换将类似于

 每个点:$ b​​ $ b X_New = X0_New +(X_Old -X0_Old)* X_Coeff 
其中
X_Coeff =(X1_New -X0_New)/(X1_Old -X0_Old)

(和Y坐标相同)


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

解决方案

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)

这篇关于计算将一个矩形的point1(x,y坐标)转换为不同矩形的Point1(x,y)的缩放因子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆