A polygon is a closed loop made up of straight line segments. When the loop does...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
A polygon is a closed loop made up of straight line segments. When the loop does not intersect itself, the polygon is said to be a simple polygon. We can think of a simple polygon as a sequence of vertices specified in counter-clockwise order. Each vertex is a point with an (z,y) coordinate. For example, the simple polygon Q = {w, v1, 22, 23, 24, 25, U6) in Figure 1(a) has 7 vertices and 7 edges. No V₂ DV4 V₂ NO P V₂ (a) (b) Figure 1: (a) Q is a simple polygon. (b) P is a convex polygon. A conver polygon is a simple polygon whose shape satisfies the property that as we walk around the boundary of the polygon in counter-clockwise order, we always turn left at each vertex. (Another way to define a convex polygon is that for any two points on or within the polygon, the straight line segment connecting those points lies entirely within the polygon.) See Figure 1(b) for an example of a convex polygon P = {0, 1₁, 12, 13, 14, 15, 16, 17) with 8 vertices. In this problem, you are asked to implement a Point class, a SimplePoly class, a ConvPoly class, an EquiTriangle class, a Rectangle class, and a Square class. Instances of the SimplePoly class contain a collection of Point instances. The ConvPoly class is a sub- class of SimplePoly, the EquiTriangle and Rectangle classes are sub-classes of ConvPoly, and the Square class is a sub-class of Rectangle. Create a module called problem1.py to contain all these classes. Further details are provided below. Point class (12 points). Instances of this class are points in two-dimensional space. Hence, each instance has an z coordinate and a y coordinate. We first state a few definitions. See Figure 2 for illustrations. • Translation: If a point (r, y) is translated (moved) by an amounts in the r direction and an amount t in the y direction, its new coordinates are (z+s,y+t). • Rotation: If a point (x, y) is rotated by angle about the origin, its new coordinates are (z cos 0-ysine, zsin 0 + y cos 0). • Distance: The distance between two points (21.91) and (12, 9/2) is √(1-22)² + (31-32)². Sidedness: Let p = (Pr.Py), q= (gr. gy), and r = (Tr.ry) be three points. We say that p lies to the left of qr (that is, the points < q, r,p> make a left turn) if and only if (rapy - Pary) + (9zry-9xPy) + (qPzqyra)>0. We say that p lies to the right of gr (that is, the points < q, r,p> make a right turn) if and only if (TzPy-Pry)+(9zry-qzPy)+(9yPs-qyrz) <0. Finally, p, q, and r are collinear (all lie on a straight line) if and only if (r-Py-Pary) + (gry-grpy) + (9yPqyrs) = 0. Translation of p Rotation of p=(x,y) (c) Figure 2: (a) Translation and rotation of a point p. (b) p lies to the left of gr. (c) p lies to the right of qr. (b) Methods for the Point class are described below: 1. init: The constructor sets the values of the z and y coordinates of the point. The default values for the point is (0,0). 2. translate: Translates the point by (s, t). The instance is modified after this method is called. 3. rotate: Rotates the point by an angle 0. The instance is modified after this method is called. 4. distance: Returns the distance between the point and another point p. Hence this method has one parameter, namely a point p. 5. left of: This method has two parameters q and r. It returns True if the point lies to the left of qr, and False otherwise. 6. right of: This method has two parameters q and r. It returns True if the point lies to the right of qr, and False otherwise. 7. str: Returns a string representation of the point. Use the usual notation to represent a point as its az and y coordinates surrounded by parentheses. 8. repr.: Returns a string representation of the point. SimplePoly class (25 points). Instances of this class are simple polygons. Methods for this class are described below: 1. init. The constructor takes an arbitrary number of points as parameters, where the points are listed in counter-clockwise order about the boundary. The parameter to the constructor should be of the form *vertices. Store the points in a list. You are not required to check the polygon for simplicity, i.e., that no two segments of the polygon intersect. 2. translate: Translates the simple polygon by (s, t). This is equivalent to translating every vertex of the polygon by (s, t). 3. rotate: Rotates the simple polygon by angle 6. This is equivalent to rotating every vertex of the polygon by 0. 4. iter: Return an iterator. This should be an instance of a new iterator class. Make sure you include a next method in that class, which should raise the StopIteration exception suitably. 5. len: This method allows us to use the built-in function len with simple polygon instances (just as str allows us to use the built-in function str). It returns the number of vertices in the polygon. 6. getitem Overload the index operator. If the parameters of this method are: self and i, it returns the i-th vertex of the convex polygon. If the index is out of range (less than zero or greater than or equal to the number of vertices of the polygon), raise the IndexError exception. 7._str_: Produces a string representation of the polygon. One obvious way to do this is to return a string containing the vertices of the polygon in counter-clockwise order. 8. perimeter: Return the perimeter of the polygon. Hint: Use the distance method for points. ConvPoly class (15 points). Instances of this class are convex polygons. Since a convex polygon is a simple polygon, this class is a subclass of the SimplePoly class. This class customizes one method, namely the constructor. All other methods are inherited. 1. __init__. As for simple polygons, the constructor takes an arbitrary number of points as parameters, where the points are listed in counter-clockwise order about the boundary. The parameter to the constructor should be of the form *vertices. Store the points in a list. You are required to check that the vertices indeed form a convex polygon. If they do not, raise an exception. (Hint: The 4 left of or right of methods will come in handy here.) If the polygon is convex, you should utilize the SimplePoly constructor to customize. EquiTriangle class (9 points). Instances of this class are equilateral triangles. Since an equilateral triangle is a convex polygon, this class is a subclass of the ConvPoly class. This class customizes one method (the constructor) and extends one method (area). 1. init: The constructor takes a single parameter (in addition to self), which is the length of the edges of the equilateral triangle. An equilateral triangle of that edge length, with one vertex at the origin is created. Note: Utilize the ConvPoly constructor to customize. 2. area: Returns the area of the equilateral triangle. Rectangle class (9 points) Instances of this class are rectangles. Since a rectangle is a convex polygon, this class is a subclass of the ConvPoly class. 1. init: The constructor takes two parameters (in addition to self), which are the length and width of the rectangle. A rectangle of those dimensions, with one vertex at the origin is created. Note: Utilize the ConvPoly constructor to customize. 2. area: Returns the area of the rectangle. Square class (5 points) Instances of this class are squares. Since a square is a rectangle, this class is a subclass of the Rectangle class. 1. __init: The constructor takes a single parameter (in addition to self), which is the length of the square. Note: Utilize the Rectangle constructor to customize. A polygon is a closed loop made up of straight line segments. When the loop does not intersect itself, the polygon is said to be a simple polygon. We can think of a simple polygon as a sequence of vertices specified in counter-clockwise order. Each vertex is a point with an (z,y) coordinate. For example, the simple polygon Q = {w, v1, 22, 23, 24, 25, U6) in Figure 1(a) has 7 vertices and 7 edges. No V₂ DV4 V₂ NO P V₂ (a) (b) Figure 1: (a) Q is a simple polygon. (b) P is a convex polygon. A conver polygon is a simple polygon whose shape satisfies the property that as we walk around the boundary of the polygon in counter-clockwise order, we always turn left at each vertex. (Another way to define a convex polygon is that for any two points on or within the polygon, the straight line segment connecting those points lies entirely within the polygon.) See Figure 1(b) for an example of a convex polygon P = {0, 1₁, 12, 13, 14, 15, 16, 17) with 8 vertices. In this problem, you are asked to implement a Point class, a SimplePoly class, a ConvPoly class, an EquiTriangle class, a Rectangle class, and a Square class. Instances of the SimplePoly class contain a collection of Point instances. The ConvPoly class is a sub- class of SimplePoly, the EquiTriangle and Rectangle classes are sub-classes of ConvPoly, and the Square class is a sub-class of Rectangle. Create a module called problem1.py to contain all these classes. Further details are provided below. Point class (12 points). Instances of this class are points in two-dimensional space. Hence, each instance has an z coordinate and a y coordinate. We first state a few definitions. See Figure 2 for illustrations. • Translation: If a point (r, y) is translated (moved) by an amounts in the r direction and an amount t in the y direction, its new coordinates are (z+s,y+t). • Rotation: If a point (x, y) is rotated by angle about the origin, its new coordinates are (z cos 0-ysine, zsin 0 + y cos 0). • Distance: The distance between two points (21.91) and (12, 9/2) is √(1-22)² + (31-32)². Sidedness: Let p = (Pr.Py), q= (gr. gy), and r = (Tr.ry) be three points. We say that p lies to the left of qr (that is, the points < q, r,p> make a left turn) if and only if (rapy - Pary) + (9zry-9xPy) + (qPzqyra)>0. We say that p lies to the right of gr (that is, the points < q, r,p> make a right turn) if and only if (TzPy-Pry)+(9zry-qzPy)+(9yPs-qyrz) <0. Finally, p, q, and r are collinear (all lie on a straight line) if and only if (r-Py-Pary) + (gry-grpy) + (9yPqyrs) = 0. Translation of p Rotation of p=(x,y) (c) Figure 2: (a) Translation and rotation of a point p. (b) p lies to the left of gr. (c) p lies to the right of qr. (b) Methods for the Point class are described below: 1. init: The constructor sets the values of the z and y coordinates of the point. The default values for the point is (0,0). 2. translate: Translates the point by (s, t). The instance is modified after this method is called. 3. rotate: Rotates the point by an angle 0. The instance is modified after this method is called. 4. distance: Returns the distance between the point and another point p. Hence this method has one parameter, namely a point p. 5. left of: This method has two parameters q and r. It returns True if the point lies to the left of qr, and False otherwise. 6. right of: This method has two parameters q and r. It returns True if the point lies to the right of qr, and False otherwise. 7. str: Returns a string representation of the point. Use the usual notation to represent a point as its az and y coordinates surrounded by parentheses. 8. repr.: Returns a string representation of the point. SimplePoly class (25 points). Instances of this class are simple polygons. Methods for this class are described below: 1. init. The constructor takes an arbitrary number of points as parameters, where the points are listed in counter-clockwise order about the boundary. The parameter to the constructor should be of the form *vertices. Store the points in a list. You are not required to check the polygon for simplicity, i.e., that no two segments of the polygon intersect. 2. translate: Translates the simple polygon by (s, t). This is equivalent to translating every vertex of the polygon by (s, t). 3. rotate: Rotates the simple polygon by angle 6. This is equivalent to rotating every vertex of the polygon by 0. 4. iter: Return an iterator. This should be an instance of a new iterator class. Make sure you include a next method in that class, which should raise the StopIteration exception suitably. 5. len: This method allows us to use the built-in function len with simple polygon instances (just as str allows us to use the built-in function str). It returns the number of vertices in the polygon. 6. getitem Overload the index operator. If the parameters of this method are: self and i, it returns the i-th vertex of the convex polygon. If the index is out of range (less than zero or greater than or equal to the number of vertices of the polygon), raise the IndexError exception. 7._str_: Produces a string representation of the polygon. One obvious way to do this is to return a string containing the vertices of the polygon in counter-clockwise order. 8. perimeter: Return the perimeter of the polygon. Hint: Use the distance method for points. ConvPoly class (15 points). Instances of this class are convex polygons. Since a convex polygon is a simple polygon, this class is a subclass of the SimplePoly class. This class customizes one method, namely the constructor. All other methods are inherited. 1. __init__. As for simple polygons, the constructor takes an arbitrary number of points as parameters, where the points are listed in counter-clockwise order about the boundary. The parameter to the constructor should be of the form *vertices. Store the points in a list. You are required to check that the vertices indeed form a convex polygon. If they do not, raise an exception. (Hint: The 4 left of or right of methods will come in handy here.) If the polygon is convex, you should utilize the SimplePoly constructor to customize. EquiTriangle class (9 points). Instances of this class are equilateral triangles. Since an equilateral triangle is a convex polygon, this class is a subclass of the ConvPoly class. This class customizes one method (the constructor) and extends one method (area). 1. init: The constructor takes a single parameter (in addition to self), which is the length of the edges of the equilateral triangle. An equilateral triangle of that edge length, with one vertex at the origin is created. Note: Utilize the ConvPoly constructor to customize. 2. area: Returns the area of the equilateral triangle. Rectangle class (9 points) Instances of this class are rectangles. Since a rectangle is a convex polygon, this class is a subclass of the ConvPoly class. 1. init: The constructor takes two parameters (in addition to self), which are the length and width of the rectangle. A rectangle of those dimensions, with one vertex at the origin is created. Note: Utilize the ConvPoly constructor to customize. 2. area: Returns the area of the rectangle. Square class (5 points) Instances of this class are squares. Since a square is a rectangle, this class is a subclass of the Rectangle class. 1. __init: The constructor takes a single parameter (in addition to self), which is the length of the square. Note: Utilize the Rectangle constructor to customize.
Expert Answer:
Answer rating: 100% (QA)
import math class Point def initself x y selfx x selfy y def rotateself angle anglerad mathradiansan... View the full answer
Related Book For
Fundamentals of Cost Accounting
ISBN: 978-0077398194
3rd Edition
Authors: William Lanen, Shannon Anderson, Michael Maher
Posted Date:
Students also viewed these programming questions
-
R and R patented this process with the 'Baby Boomer' generation in mind. This is the demographic of the population between the ages of 57 and 75. They are the market that is most likely to place an...
-
CHOOSE THE CORRECT ANSWER: 1. If R & S is true, then which of the following is correct? A. R is true. B. R is false. C. R could be true or false. 2. If R & S is false, then which of the...
-
R = 5 with probability 0.25, R = 0.25 with probability 0.25, R = 1 with probability 0.5. Find the arithmetic and geometric means of the random variables R for per capita production in the above...
-
Coffin Corporation appropriately uses the installment-sales method of accounting to recognize income in its financial statements. The following information is available for 2014 and 2015....
-
In 1992, Lincoln Company completed the construction of a building at a cost of $4,000,000 and first occupied it in January 1995. It was estimated that the building will have a useful life of 40 years...
-
A six-column table for JKL Company follows. The first two columns contain the unadjusted trial balance for the company as of July 31, 2017. The last two columns contain the adjusted trial balance as...
-
How many degrees of freedom are there? Exercises 1015 refer to the following data: Anthropologists can estimate the birthrate of an ancient society by studying the age distribution of skeletons found...
-
Zoso is a rental car company that is trying to determine whether to add 25 cars to its fleet. The company fully depreciates all its rental cars over five years using the straight-line method. The new...
-
Question 2 :The price of a Big Mac in the London is 3.29 and the price in Zurich is SFr 6.5.Using the Big Mac Index, one may calculate the implied PPP exchange rate.The actual quoted exchange rate is...
-
Refer to Exercise 3.95. Given that a student, selected at random, is found to have an extensive understanding of physics, what is the probability that the student has (a) an extensive understanding...
-
There are both positive and negative behaviors in group communication. do you thing is the most harmful? 1. Which of the negative group roles/behaviors, 2. Justify your answer/Why?
-
Chavez Corporation reported the following data for the month of July: Inventories: Beginning Ending Raw materials $45,000 $39,000 Work in process $25,000 $35,000 Finished goods $41,000 $56,000...
-
Buddy was badly injured on April 1, 2021 while skiing at Candy Cane Mountain. He brought a civil action in federal district court against the owner of the ski area, North Pole, Inc., claiming that...
-
need help understanding the following question Windows vs Mac OS Apple's Mac OS is a major competitor for Microsoft Windows, and many people feel very strongly about choosing one over the other. Some...
-
1. The Treaty on European Union (Maastricht Treaty): a) three pillars of the EU; b) competences and the institutional system; c) EU citizenship and the protection of fundamental rights. 2. The EU...
-
Demarco and Janine Jackson have been married for 20 years and have four children (no children under age 6 at year- end) who qualify as their dependents (Damarcus, Jasmine, Michael, and Candice). The...
-
Consider a market with an incumbent firm, a potential entrant and a buyer with demand D(p) = 180-p. Suppose the potential entrant is more efficient than the incumbent. The entrant has a unit...
-
A. Select a recent issue (paper or online) of Report on Business Magazine, Canadian Business Magazine (online only), Bloomberg Businessweek, Fast Company, The Economist, or another business magazine....
-
Cochise Corporations Southern Division is operating at capacity. It has been asked by Northern Division to supply it a thermal switch, which Southern sells to its regular customers for $60 each....
-
Leidenheimer Corporation manufactures small airplane propellers. Sales for year 2 totaled $1,700,000. Information regarding resources for the month follows: In addition, Leidenheimer spent $50,000 on...
-
Assume that Cold Rock sells ice cream for $4.80 per gallon. The cost of each gallon follows: Materials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . $1.80...
-
a. What responsibility does the auditor have when he believes material errors or irregularities may exist? b. What are the possible effects of the foregoing on the auditor's standard report?
-
Watts and Williams, a firm of certified public acccountants, audited the accounts of Sampson Skins, Inc., a corporation that imports and deals in fine furs. Upon completion of the examination the...
-
a. Can an examination made in accordance with generally accepted auditing standards be relied upon to detect illegal acts? Why or why not? b. What are the possible effects of illegal acts on the...
Study smarter with the SolutionInn App