Mapping points inside one 2D rectangle into another smaller one

Click For Summary

Discussion Overview

The discussion revolves around the problem of mapping points from a rotated and translated larger 2D rectangle to a smaller rectangle with a fixed orientation in the coordinate system. Participants explore various approaches to achieve this transformation, considering the effects of rotation, translation, and scaling.

Discussion Character

  • Exploratory
  • Technical explanation
  • Mathematical reasoning
  • Debate/contested

Main Points Raised

  • One participant describes the need to map points from a larger rectangle to a smaller one, emphasizing the larger rectangle's potential rotation and translation.
  • Another participant suggests a method involving translation to the top left corner followed by scaling, providing a transformation matrix for the mapping.
  • A participant points out a misunderstanding regarding the corners of the larger rectangle, clarifying that the orientation affects the mapping process.
  • Concerns are raised about the arbitrary orientation of the larger rectangle, leading to discussions about the necessity of a different transformation for various angles of rotation.
  • One participant proposes composing translation and rotation matrices to handle arbitrary orientations, while another suggests a more general transformation matrix for mapping points.
  • There is a discussion about the implications of flipping the y-axis in the coordinate system, which affects the results of the transformation.
  • A participant notes that the proposed solution worked but required negating the results for certain points, indicating a potential issue with the coordinate system orientation.

Areas of Agreement / Disagreement

Participants express differing views on the correct approach to handle the transformation, particularly regarding the orientation and scaling of the rectangles. There is no consensus on a single method, as various models and transformations are proposed and debated.

Contextual Notes

Participants acknowledge the complexity introduced by the arbitrary rotation of the larger rectangle and the need for a transformation that accommodates this variability. The discussion highlights the importance of understanding the coordinate system's orientation in relation to the transformation process.

Who May Find This Useful

This discussion may be useful for individuals interested in geometric transformations, computer graphics, or any applications involving mapping between different coordinate systems in 2D space.

xovangam
Messages
18
Reaction score
0
in some work I'm doing i have a 2D rectangle that can be rotated and/or translated in any direction in 2D space. for example it might look like this:

Code:
(x=30,y=-10) +-----------+ (x=30,y=2)              +-- +y
                   |                |                              |
                   |    *P         |                              -x
(x=20,y=-10) +-----------+ (x=20,y=2)

i would like for that to map to another smaller 2D rectangle that has its origin fixed at the top left corner. such that if i pick some point (P) that's on the larger rectangle i want to map it to the coordinate space of the smaller rectangle:

Code:
(x=0,y=0) +-------+ (x=5,y=0)                          +-- +x
              |           |                                        |
              |  *P      |                                        +y
(x=0,y=3) +-------+ (x=5,y=3)

not quite sure how to go about setting that up...any thoughts?

TIA
 
Physics news on Phys.org
Hi xovangam! :smile:

There are quite few ways in which to achieve this. The most simp way is to translate the rectangle first to the top left corner and then shrinking it accordingly.

Some notation:
Let (x_0,y_0) be the top left corner of the original rectangle, let (x_1,y_1) be the top right corner and let (x_2,y_2) be the bottom left corner.
Let (x_1^\prime,0) be the top right corner of the new rectangle and let (0,y_2^\prime) be the bottom left corner. In your example, we have

(x_0,y_0)=(30,-10)
(x_1,y_1)=(20,-10)
(x_2,y_2)=(30,2)
(x_1^\prime,0)=(5,0)
(0,y_2^\prime)=(0,3)

The function you are looking for is

\left(\begin{array}{c} x\\ y\\ \end{array}\right) =<br /> \left(\begin{array}{cc} \frac{x_1^\prime}{x_1-x_0} &amp; 0\\ 0 &amp; \frac{y_2^\prime}{y_2-y_0}\\ \end{array}\right)<br /> \left(\begin{array}{c} x-x_0\\ y-y_0\\ \end{array}\right)<br />

And indeed, we have here that (30,-10) is mapped to (0,0), that (20,-10) is mapped to (5,0) and that (30,2) is mapped to (0,3).
 
thanks for the response micromass!

however, if (x1,y1) is the top right corner of the larger rectangle then it would be (30,2) and not (20,-10) as you state using my example. and that actually is what demonstrates the issue i have in that in this example the larger rectangle has been rotated such that it is oriented +y from the left to the right side on the top and bottom, and the smaller rectangle differs in that it has +x in that same direction. but i still want to project points inside the larger rectangle at that orientation into the smaller rectangle. so it's almost like i need a change of basis or something, but I'm not quite sure how to put that into the transformation matrix.
 
xovangam said:
thanks for the response micromass!

however, if (x1,y1) is the top right corner of the larger rectangle then it would be (30,2) and not (20,-10) as you state using my example. and that actually is what demonstrates the issue i have in that in this example the larger rectangle has been rotated such that it is oriented +y from the left to the right side on the top and bottom, and the smaller rectangle differs in that it has +x in that same direction. but i still want to project points inside the larger rectangle at that orientation into the smaller rectangle. so it's almost like i need a change of basis or something, but I'm not quite sure how to put that into the transformation matrix.

Ah, you do want the rotation?? I just thought you messed up the drawing for some reason :biggrin: I'm sorry, I should have asked.

Anyway, you have

(x0,y0)=(30,−10)
(x1,y1)=(30,2)
(x2,y2)=(20,-10)
(x′1,0)=(5,0)
(0,y′2)=(0,3)

Anyway, then the matrix should be

\left(\begin{array}{c} x\\ y\\ \end{array}\right) = <br /> \left(\begin{array}{cc} 0 &amp; \frac{y^\prime}{y_1-y_0}\\ \frac{x^\prime}{x_2-x_0} &amp; 0\\ \end{array}\right)<br /> \left(\begin{array}{c} x-x_0\\ y-y_0\\ \end{array}\right)<br />
 
what if i don't know what the orientation of the larger rectangle is, i.e. it could be any arbitrary rotation. in the example i gave (perhaps a poor choice) it is rotated exactly 90 degrees, but it may also be rotated say, only 10 degrees instead. the orientation of the rectangle is an unknown factor in this case (though i guess i could compute that relative to the standard R2 basis vectors).

anyway so if the larger rectangle is arbitrarily oriented about the X and Y axes in 2D space that would require a different transform correct? again the smaller rectangle that i want to map to is always oriented in the same way with (0,0) in the top left corner, +X to the right and +Y down.

i've attached 2 GIFs to try and better visualize what i would like to do.
 

Attachments

  • large.gif
    large.gif
    3.1 KB · Views: 633
  • small.gif
    small.gif
    1.9 KB · Views: 624
Last edited:
If you want a generic rotation about an arbitrary point just compose translation and rotation matrices to achieve your transform. If you need to scale, then again compose them with the other transformations.

Just make sure you do the composition of maps in the right order.
 
OK, let's do this in complete generality.

Let's say that your first rectangle is described by (x0,y0),(x1,y1),(x2,y2). And your second rectangle is described by (x0',y0'),(x1',y1'),(x2',y2') And you want to send (xi,yi) to (xi',yi'). Then your transformation should be

\left(\begin{array}{c} x\\ y\\ \end{array}\right) = <br /> \left(\begin{array}{cc}<br /> \frac{(y_1-y_0)(x_2^\prime-x_0^\prime)-(y_2-y_0)(x_1^\prime-x_0^\prime)}{(x_2-x_0)(y_1-y_0)-(x_1-x_0)(y_2-y_0)} &amp; \frac{(x_1-x_0)(x_2^\prime-x_0^\prime)-(x_2-x_0)(x_1^\prime-x_0^\prime)}{(x_1-x_0)(y_2-y_0)-(x_2-x_0)(y_1-y_0)}\\<br /> \frac{(y_1-y_0)(y_2^\prime-y_0^\prime)-(y_2-y_0)(y_1^\prime-y_0^\prime)}{(x_2-x_0)(y_1-y_0)-(x_1-x_0)(y_2-y_0)} &amp; \frac{(x_1-x_0)(y_2^\prime-y_0^\prime)-(x_2-x_0)(y_1^\prime-y_0^\prime)}{(x_1-x_0)(y_2-y_0)-(x_2-x_0)(y_1-y_0)}\\<br /> \end{array}\right)<br /> \left(\begin{array}{c} x-x_0\\ y-y_0\\ \end{array}\right)<br /> +<br /> \left(\begin{array}{c} x_0^\prime\\ y_0^\prime\\ \end{array}\right)<br />
 
isn't this a change of basis though? disregarding scale, i guess I'm not clear on how i could rotate the larger rectangle within the standard R2 space and end up with the coordinate system of the smaller rectangle (where positive Y is flipped to point down with positive X still pointing to the right, but with P still at the top-left of the rectangle). i.e. I'm not sure what that transform (composed or otherwise) would look like.
 
Last edited:
that almost works :smile:

if Q in the larger rectangle is (-x,-y) however, it's coming out as (-x',-y'), which is outside the boundary of the smaller rectangle. though the values seem correct, they are just negated to the opposite (-x,-y) quadrant it looks like. maybe i set it up wrong, i will double-check..
 
  • #10
ok, so to summarize the results, the solution proposed by micromass worked (thanks!), but i had to negate the (xi',yi') result for any point (xi, yi) inside the larger rectangle that i transformed. i *think* this is because the coordinate system for the larger rectangle actually does have the y-axis flipped around (see result) such that positive Y points down instead of up (see attached).

does that make sense?
 

Attachments

  • large.gif
    large.gif
    3.1 KB · Views: 635
  • #11
xovangam said:
ok, so to summarize the results, the solution proposed by micromass worked (thanks!), but i had to negate the (xi',yi') result for any point (xi, yi) inside the larger rectangle that i transformed. i *think* this is because the coordinate system for the larger rectangle actually does have the y-axis flipped around (see result) such that positive Y points down instead of up (see attached).

does that make sense?

Yes, that makes sense. If you flip the y-axis, then you'll have to negate the result.
 
  • #12
very cool.

thank you sir you've been more than helpful!
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 26 ·
Replies
26
Views
1K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 33 ·
2
Replies
33
Views
3K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 14 ·
Replies
14
Views
2K
  • · Replies 4 ·
Replies
4
Views
4K
Replies
22
Views
5K