Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Understanding Polygons | Introduction to Geometric Modelling
Geometric Modelling with Python

Understanding Polygons

Swipe to show menu

To work with polygons in geometric modeling, you need to understand both their mathematical properties and how to represent them programmatically. A polygon is a closed, two-dimensional shape formed by connecting a sequence of straight line segments end-to-end. The points where these segments meet are called vertices (or corners), and the segments themselves are called edges.

In geometric modeling, you typically represent a polygon by listing its vertices in order. Each vertex is a point, often defined as a tuple of x and y coordinates. The last vertex connects back to the first to close the shape.

Steps to Represent a Polygon and Calculate Its Perimeter

  1. List the coordinates of each vertex in order, forming a list of tuples;
  2. Ensure the polygon is closed by connecting the last vertex back to the first;
  3. To compute the perimeter, sum the distances between consecutive vertices, including the segment from the last vertex back to the first.
123456789101112131415161718
# Define a polygon as a list of (x, y) tuples polygon = [(1, 2), (4, 6), (7, 3), (5, 1)] # Function to calculate the distance between two points def distance(p1, p2): dx = p2[0] - p1[0] dy = p2[1] - p1[1] return (dx**2 + dy**2) ** 0.5 # Calculate the perimeter of the polygon perimeter = 0 num_vertices = len(polygon) for i in range(num_vertices): p1 = polygon[i] p2 = polygon[(i + 1) % num_vertices] # Wrap around to close the polygon perimeter += distance(p1, p2) print("Perimeter:", perimeter)

This approach allows you to model any polygon by specifying its vertices in order. Calculating the perimeter requires looping through each edge, finding the distance between consecutive points, and summing these lengths. This method forms the foundation for more advanced geometric operations you will encounter in later chapters.

question mark

Which type of polygon has all sides of equal length?

Select all correct answers

Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 1. Chapter 4

Ask AI

expand

Ask AI

ChatGPT

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

Section 1. Chapter 4
some-alt