Public Group

# how do I modify a rotated rectangle

This topic is 2840 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Im trying to modify a rectangle's height while maintaining its position

its pretty easy to do this while the rectangle is not rotated but Im having lots of trouble when I have to deal with rotated rectangles

example of what I want to do
[SOURCE]    (X,Y)_______   ________	 |     |   |      |	 |     |   |      |	 |     |   |      |	 -------   |      |	           |      |	 before    |      |	           |      |	           --------			   	           after			   note: the top-left coordinate remains the same after the transformation process[\SOURCE]

##### Share on other sites
For situations like this, the optimal solution is usually to work with a local-space copy of the geometry rather than a world-space copy.

However, if you need to modify a world-space copy of the rectangle, one way to do it is as follows. Convert to rectangle to a position (which can be a corner if you want), an orthonormal basis (two mutually perpendicular unit-length vectors), and a height and width. You can derive this information from the vertices by subtracting the appropriate vertices from each other and computing the lengths of the edges.

Once you have the rectangle in this form, you can adjust the width and height as desired, and then rebuild the vertices from the modified data.

There are other ways it can be done that might be more appropriate to the context, but they'll likely be at least somewhat similar to what I described above.

##### Share on other sites
If we are only dealing with 90 degree rotations then it is not that hard.

If you want to do, rotations of smaller then that, well it gets a bit more complicated.

So for nowI am assuming 90 degree.

Just swap the width and height. That is all ya need to do. And then draw as before.

theTroll

##### Share on other sites
Ive managed to get it to local coords

how do I return it to world coords?

[SOURCE]//go local Matrix transform_matrix = Matrix.CreateTranslation(new Vector3(-origin.X, -origin.Y, 0)) * Matrix.CreateRotationZ(-rotation);Vector2 aux_origin = Vector2.Transform(new Vector2(origin.X, origin.Y), transform_matrix);// DO SOME LOCAL TRANSFORMS HERE...//return to worldtransform_matrix = Matrix.CreateTranslation(new Vector3(origin.X, origin.Y, 0)) * Matrix.CreateRotationZ(rotation);aux_origin = Vector2.Transform(aux_origin, transform_matrix);[/SOURCE]

1. 1
2. 2
Rutin
19
3. 3
4. 4
frob
13
5. 5

• 9
• 16
• 11
• 9
• 17
• ### Forum Statistics

• Total Topics
632603
• Total Posts
3007367

×