Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This question is a lab in my Python class. So the program used gonna be Python 3

ID: 3675644 • Letter: T

Question

This question is a lab in my Python class. So the program used gonna be Python 3.5.x . Thanks in advance

Because the lab is too big. A tutor recommened me to split it into multiple question.

Here is the link to the whole question.

https://www.chegg.com/homework-help/questions-and-answers/question-lab-python-class-program-used-gonna-python-35x--thanks-advance-common-real-world--q11116331

In this question I just need answer to 2 objective :

A fleshed out Mesh class (attributes, methods, docstrings, etc). (5 pts)

A project2.py driver file which instantiates the Mesh object, reads argv, calls the methods, etc. (5 pts)

Explanation / Answer

MeshPy offers quality triangular and tetrahedral mesh generation for Python. Meshes of this type are chiefly used in finite-element simulation codes, but also have many other applications ranging from computer graphics to robotics.

Example is:

  

An instance of numpy.lib.index_tricks.nd_grid which returns an dense (or fleshed out) mesh-grid when indexed, so that each returned argument has the same shape. The dimensions and number of the output arrays are equal to the number of indexing dimensions. If the step length is not a complex number, then the stop is not inclusive.

However, if the step length is a complex number (e.g. 5j), then the integer part of its magnitude is interpreted as specifying the number of points to create between the start and stop values, where the stop value is inclusive.

mesh-grid ndarrays all of the same dimensions

Adding Items to a Mesh

We can add a new vertex to the mesh by calling the add_vertex() member function. This function gets a coordinate and returns a handle to the newly inserted vertex.

vh0 = mesh.add_vertex(TriMesh.Point(0, 1, 0))

vh1 = mesh.add_vertex(TriMesh.Point(1, 0, 0))

vh2 = mesh.add_vertex(TriMesh.Point(2, 1, 0))

vh3 = mesh.add_vertex(TriMesh.Point(0,-1, 0))

vh4 = mesh.add_vertex(TriMesh.Point(2,-1, 0))

To add a new face to the mesh we have to call add_face(). This function gets the handles of the vertices that make up the new face and returns a handle to the newly inserted face:

fh0 = mesh.add_face(vh0, vh1, vh2)

fh1 = mesh.add_face(vh1, vh3, vh4)

fh2 = mesh.add_face(vh0, vh3, vh1)

We can also use a Python list to add a face to the mesh:

vh_list = [vh2, vh1, vh4]

fh3 = mesh.add_face(vh_list)

OpenMesh allows us to dynamically add custom properties to a mesh. We can add properties to vertices, halfedges, edges, faces and the mesh itself. To add a property to a mesh (and later access its value) we have to use a property handle of the appropriate type:

The following code shows how to add a vertex property to a mesh:

prop_handle = VPropHandle()

mesh.add_property(prop_handle, "cogs")

The second parameter of the function add_property() is optional. The parameter is used to specify a name for the new property. This name can later be used to retrieve a handle to the property using the get_property_handle() member function.

Now that we have added a vertex property to the mesh we can set and get its value. Here we will use the property to store the center of gravity of each vertex' neighborhood:

for vh in mesh.vertices():

cog = TriMesh.Point(0,0,0)

valence = 0

for neighbor in mesh.vv(vh):

cog += mesh.point(neighbor)

valence += 1

mesh.set_property(prop_handle, vh, cog / valence)

Properties use Python's type system. This means that we can use the same property to store values of different types (e.g. store both strings and integers using the same vertex property). Properties are initialized to the Python built-in constant None.

To remove a property we have to call remove_property() with the appropriate property handle:

mesh.remove_property(prop_handle)

  

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote