Question: IN PYTHON Determine the edges of the polygon. The difficulty here is that the vertices are unstructured; the data doesnt say that vertices 0 and

IN PYTHON Determine the edges of the polygon. The difficulty here isIN PYTHON

Determine the edges of the polygon.

The difficulty here is that the vertices are unstructured; the data doesnt say that vertices 0 and 5 form an edge, for example. To overcome this, we observe that for a convex polygon, the vertices wind around the center of mass. Thus, write a function that 1

. Accepts the xy data and the indices of the vertices of one of the polygons

2. Computes the center of mass: (xm, ym) = (average of xs, average of y)

3. Calculates the angles formed between the vertices and the center of mass. Here, use atan2

4. Orders the indices according to increasing angle

5. Return a list of edges

For example, face 1 has vertices 3, 1, 4, and 5 in no particular order. In terms of increasing angle, the vertices are ordered 3, 4, 1, 5. The function would return the four edges (3,4), (4,1), (1,5) and (5,3).

1 0 3 2 S To represent this data, the author provides a file polygons.dat containing the lines f2v = {0:{0, 5, 1}, 1:{1, 5, 3, 4}, 2:{0, 2, 5}} [(6.4,0), (20.6,12), (12.7,-15), (37,7), (37,15), (22.5, -5.2)] = 1 0 3 2 S To represent this data, the author provides a file polygons.dat containing the lines f2v = {0:{0, 5, 1}, 1:{1, 5, 3, 4}, 2:{0, 2, 5}} [(6.4,0), (20.6,12), (12.7,-15), (37,7), (37,15), (22.5, -5.2)] =

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!