Problem 35 Compute Area Arbitrary Triangle Arbitrary Tri Angle Described Coordinates Three Q43800555
Problem 3.5. Compute the area of an arbitrary triangle An arbitrary tri- angle can be described by the coordinates of its three vertices: (r1, yl), (x2, y2), (r3, y3), numbered in a counterclockwise direction. The area of the triangle is given by the formula GT2y3 – 1342 – 11y3 + *3y1 +*1¥2 – 12y1| Write a function t riangle_area(vertices) that returns the area of a triangle whose vertices are specified by the argument vertices, which is a nested list of the vertex coordinates. Make sure your implementation passes the following test function, which also illustrates how the triangle_area function works: def test triangle_area(): Verify the area of a triangle with vertices (0,0), (1,0), and (0,2). v1 = (0,0); v3 = (0,2) v2 = (1,0); [v1, v2, v3] vertices = expected computed = triangle area(vertices) tol = 1E-14 success = abs (expected computed) < tol msg = f”computed area={computed} != {expected}(expected)” assert success, msg Language: python Show transcribed image text Problem 3.5. Compute the area of an arbitrary triangle An arbitrary tri- angle can be described by the coordinates of its three vertices: (r1, yl), (x2, y2), (r3, y3), numbered in a counterclockwise direction. The area of the triangle is given by the formula GT2y3 – 1342 – 11y3 + *3y1 +*1¥2 – 12y1| Write a function t riangle_area(vertices) that returns the area of a triangle whose vertices are specified by the argument vertices, which is a nested list of the vertex coordinates. Make sure your implementation passes the following test function, which also illustrates how the triangle_area function works: def test triangle_area(): Verify the area of a triangle with vertices (0,0), (1,0), and (0,2). v1 = (0,0); v3 = (0,2) v2 = (1,0); [v1, v2, v3] vertices = expected computed = triangle area(vertices) tol = 1E-14 success = abs (expected computed)
Expert Answer
Answer to Problem 3.5. Compute the area of an arbitrary triangle An arbitrary tri- angle can be described by the coordinates of it…
OR