Question: Write the function signedArea that takes three parameters A, B, and C, representing the three vertices of an oriented triangle, and returns the signed
Write the function signedArea that takes three parameters A, B, and C, representing the three vertices of an oriented triangle, and returns the signed area of the triangle ABC. Each parameter is a tuple of 2 floats, representing a point in 2-space. 2-space is our term for two dimensional space, like the floor of your room, but a really large room. The signed area of the oriented triangle ABC in 2-space is the area of the triangle, but positive if ABC defines a left turn (counterclockwise) and negative if ABC defines a right turn (clockwise). For example, if A=(1,1), B=(3,1), C=(3,2), then the signed area of the triangle ABC is 1.0, and the signed area of the triangle ACB is -1.0. 2 To calculate the signed area of the triangle ABC, use the following facts. The vector between two points P and Q is Q - P (component-wise subtraction: for example, (2,1) - (.5,.3) is (1.5,.7)). The signed area of the triangle spanned by vectors V = (vo, v) and W = (wo, W) is vo*w1_v1* Another way of thinking of this result: if we let O = (0, 0) be the origin in 2-space, P = (Po, P) and Q (90,91) be arbitrary points in 2-space, then the signed area of the triangle OPQ is Po*q1p1*qo Note: this function allows you to determine whether you are turning left or right as you move around a polygon (how?). This will be useful later in the Graham scan algorithm for computing the convex hull of a polygon. = 2 areaPolygon (p) Write the function areaPolygon that takes a list p of tuples, representing the vertices of a polygon, sorted counterclockwise around the polygon, and returns the area of the polygon. The area of a polygon may be decomposed into the sum of the signed areas of a collection of triangles built by walking around the polygon. In particular, if the polygon vertices moving counterclockwise around the polygon are po, P1,..., Pk and if O is the origin (0,0) in 2-space, then the polygon area is the sum of the signed areas of the triangles Opop1, Op1P2,..., OpkPo. (If you walk around the polygon in the clockwise direction, then the sum of the signed areas will be the negative area of the polygon.) Your code should use the signedArea function you designed above. We will explain why this works in lecture. Note: It turns out that you could replace the origin O by any other fixed point in 2-space: choosing the origin simplies the computation. See over for additional context on the improveFilename function.
Step by Step Solution
3.59 Rating (170 Votes )
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
