Rect position relative to point

36 views Asked by At

i've quite noob geometry question. I have first rect, for example R1(0,0,320, 240), a point P1(20,40), and second rect R2(0,0,640,480), with point P2(40,80) i would like to calculate the position of 2nd rect, that makes two points share one position. In this case it's ofc R2(-20,-40,600, 440), but i need universal formula. I know it's silly, but i've spend 3 hours and can't find answer. Thanks!

1

There are 1 answers

0
MBo On
 r1.left + p1.x = r2.left + p2.x + x_shift
 so
 x_shift = r1.left + p1.x - r2.left - p2.x

the same logic for y-coordinate