rectangle rotation
-
Hello, please help me to write a function rotate that will rotate the rectangle 45 degrees each time button is pressed let say that rectangle values are as follows rectangle[0].x=250.0; rectangle[0].y=100.0; rectangle[1].x=550.0; rectangle[1].y=100.0; rectangle[2].x=550.0; rectangle[2].y=300.0; rectangle[3].x=250.0; rectangle[3].y=300.0; i know that it should be something like H2 = H·cosθ + W·sinθ W2 = H·sinθ + W·cosθ where H2 is the height of the rotated rectangles and W2 is the width. i need an assistance in writing this function.. please help
-
Hello, please help me to write a function rotate that will rotate the rectangle 45 degrees each time button is pressed let say that rectangle values are as follows rectangle[0].x=250.0; rectangle[0].y=100.0; rectangle[1].x=550.0; rectangle[1].y=100.0; rectangle[2].x=550.0; rectangle[2].y=300.0; rectangle[3].x=250.0; rectangle[3].y=300.0; i know that it should be something like H2 = H·cosθ + W·sinθ W2 = H·sinθ + W·cosθ where H2 is the height of the rotated rectangles and W2 is the width. i need an assistance in writing this function.. please help
1. Decide what point is to be the centre of rotation. Let's call it O, with co-ordinates (Xo, Yo). 2. Rotate each point of the rectangle, Pi, with co-ordinates (Xi, Yi), around O, producing a new point, Pi', with co-ordinates (Xi', Yi'). You do this using the following two identities:
Xi' = (Xi-Xo)cosθ - (Yi-Yo)sinθ
Yi' = (Xi-Xo)sinθ + (Yi-Yo)cosθYou now have your rotated rectangle! This page[^] may help.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
-
1. Decide what point is to be the centre of rotation. Let's call it O, with co-ordinates (Xo, Yo). 2. Rotate each point of the rectangle, Pi, with co-ordinates (Xi, Yi), around O, producing a new point, Pi', with co-ordinates (Xi', Yi'). You do this using the following two identities:
Xi' = (Xi-Xo)cosθ - (Yi-Yo)sinθ
Yi' = (Xi-Xo)sinθ + (Yi-Yo)cosθYou now have your rotated rectangle! This page[^] may help.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
umm what i have in my code is something like: px = (rectwidth/2); py = (rectheight/2); so i assume that they represent my center through which i want to rotate my rectangle (px, py) however, i am not sure how to represent all of the point of the rect to be Xi Yi considering that my rectangle representaion is as mentioned in the previous post with co-ordinates of (250, 100) is rectangle[0] (550, 100) is rectangle[1] (550, 300) is rectangle[2] (250, 300) is rectangle[3] i am new to C++ so i am having trouble seeing how your equasion can be programmed. i do understand the equasions u've provided though. Please any suggestions on the programming? like:
void rotate (float angle)
{
? = (? - px)cos(angle) - (? - py)sin(angle);
? = (? - px)sin(angle) + (? - py)cos(angle);
}not sure what should be in there.
-
umm what i have in my code is something like: px = (rectwidth/2); py = (rectheight/2); so i assume that they represent my center through which i want to rotate my rectangle (px, py) however, i am not sure how to represent all of the point of the rect to be Xi Yi considering that my rectangle representaion is as mentioned in the previous post with co-ordinates of (250, 100) is rectangle[0] (550, 100) is rectangle[1] (550, 300) is rectangle[2] (250, 300) is rectangle[3] i am new to C++ so i am having trouble seeing how your equasion can be programmed. i do understand the equasions u've provided though. Please any suggestions on the programming? like:
void rotate (float angle)
{
? = (? - px)cos(angle) - (? - py)sin(angle);
? = (? - px)sin(angle) + (? - py)cos(angle);
}not sure what should be in there.
OK - for 'Pi', read 'rectangle[i]', for i in the range 0 to 3. So, for rectangle, assuming you're transforming rectangle into a new rectangle, rectangleNew:
void rotate (float angle)
{
rectangleNew[0].x = (rectangle[0].x - px) * cos(angle) - (rectangle[0].y - py) * sin(angle);
rectangleNew[0].y = (rectangle[0].x - px) * sin(angle) + (rectangle[0].y - py) * cos(angle);
rectangleNew[1].x = (rectangle[1].x - px) * cos(angle) - (rectangle[1].y - py) * sin(angle);
rectangleNew[1].y = (rectangle[1].x - px) * sin(angle) + (rectangle[1].y - py) * cos(angle);
rectangleNew[2].x = (rectangle[2].x - px) * cos(angle) - (rectangle[2].y - py) * sin(angle);
rectangleNew[2].y = (rectangle[2].x - px) * sin(angle) + (rectangle[2].y - py) * cos(angle);
rectangleNew[3].x = (rectangle[3].x - px) * cos(angle) - (rectangle[3].y - py) * sin(angle);
rectangleNew[3].y = (rectangle[3].x - px) * sin(angle) + (rectangle[3].y - py) * cos(angle);
}Don't try and rotate points in-place...
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
-
Hello, please help me to write a function rotate that will rotate the rectangle 45 degrees each time button is pressed let say that rectangle values are as follows rectangle[0].x=250.0; rectangle[0].y=100.0; rectangle[1].x=550.0; rectangle[1].y=100.0; rectangle[2].x=550.0; rectangle[2].y=300.0; rectangle[3].x=250.0; rectangle[3].y=300.0; i know that it should be something like H2 = H·cosθ + W·sinθ W2 = H·sinθ + W·cosθ where H2 is the height of the rotated rectangles and W2 is the width. i need an assistance in writing this function.. please help
If you want to see a VERY well written (I'm biased) article which has a lot of transformation work with matrices, look at: Warping Coordinates with Matrices[^] I like to think my diagrams will help you also. Iain.
In the process of moving to Sweden for love (awwww). If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), give me a job!