The distance between two points is: $$ d = \sqrt{(x_2 - x_1)^2 + (y_2 - y_1)^2}$$
Write this program yourself before looking at the approaches below.Notes and Code | Outcome |
---|---|
Procedural: Basic |
Show Notes ▼
perimeter-p.py
Show Notes ▼
|
Procedural: Using a distance function |
Show Notes ▼
perimeter-p.py
Show Notes ▼
|
Object Oriented: Using a point classUses a point class with a distanceTo method that calculates the distance to another point. |
Show Notes ▼
perimeter-oo.py
Show Notes ▼
|
Object Oriented: Using a point class and a triangle classUses a point class with a distanceTo method that calculates the distance to another point and a triangle class that calculates the perimeter. |
Show Notes ▼
perimeter-oo.py
Show Notes ▼
|
Assignment: Area of a triangleWrite a program to calculate the area of the triangle.You can use Heron's formula to determine the area of a triangle based on the lengths of its sides, or there is a formula you can use based on the vertices of triangle. |
Output:
Show Notes ▼
|
Assignment: Find the perimeter of a polygon.Find the perimeter of the polygon. Explain which method you used and why.The distance between two points is: $$ d = \sqrt{(x_2 - x_1)^2 + (y_2 - y_1)^2}$$ |
Output:
Show Notes ▼
|
Assignment: Find the Area of a polygon.Find the area of the polygon. A convex polygon can be broken down into triangles. |
Output:
Show Notes ▼
|