Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Rotation of Shapes | Geometric Transformations
Geometric Modelling with Python

Rotation of Shapes

Swipe to show menu

To rotate a geometric figure, such as a polygon, around a point (often the origin), you use a specific mathematical formula. When you rotate a point (x, y) around the origin by an angle θ (measured in radians), the new coordinates (x', y') are calculated as follows:

  • x' = x * cos(θ) - y * sin(θ);
  • y' = x * sin(θ) + y * cos(θ).

This formula is derived from trigonometry and describes how each point moves along a circular arc centered at the origin. In Python, you can use the math module to access the sine and cosine functions, and the angle must be in radians for these functions.

Apply this formula step by step. Suppose you want to rotate a triangle with vertices at (1, 0), (0, 1), and (-1, 0) by 90 degrees (which is π/2 radians) around the origin. For each vertex, you substitute the x and y values into the formula above and calculate the new position. Doing this for all vertices gives you the rotated triangle.

In geometric modelling, you often work with polygons represented as lists of points. To rotate an entire polygon, you apply the rotation formula to each vertex in the list. This approach allows you to transform any polygon, regardless of the number of sides, by simply iterating through its points and updating their positions.

12345678910111213141516171819202122232425
import math def rotate_polygon(points, angle_radians): """Rotate a polygon around the origin by a specified angle. Args: points: List of (x, y) tuples representing the polygon's vertices. angle_radians: The rotation angle in radians. Returns: List of (x', y') tuples representing the rotated vertices. """ cos_theta = math.cos(angle_radians) sin_theta = math.sin(angle_radians) rotated = [] for x, y in points: x_new = x * cos_theta - y * sin_theta y_new = x * sin_theta + y * cos_theta rotated.append((x_new, y_new)) return rotated # Example usage: triangle = [(1, 0), (0, 1), (-1, 0)] rotated_triangle = rotate_polygon(triangle, math.pi / 2) print(rotated_triangle)
question mark

What is a true statement about the effect of rotating a polygon by 90 degrees around the origin?

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 2. Chapter 3

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

Section 2. Chapter 3
some-alt