Question: please use python and # to explain what you are doing. please be aware there are hidden test these pictures are all apart of one
please use python and # to explain what you are doing. please be aware there are hidden test



these pictures are all apart of one question.
you have to write code that runs the test AND hidden test perfectly. the code needed is for the test at the end that are labeled un green (ex. 5pts, 10pts) . the code should run the hidden test. I have reuploaded the photos. If you can not complete please reassign
- Problem: Fractals We want to have a bit of fun genrating fractals. Let's first write a function that, given a sequence of (xy) points, draws the corresponding polygon: Laport natplot.1b.pyp.ot as pl: def draw polygon [ccorde, closet=true); co = 11st(coords) fix, ax - plz subplots[1, 1) if closed and co[0] !- co[-111 co.appeod co[0]) Repent first point xe, ye - spicc). Splits coordinates ax.set_aspectl'equal', 'box' ax.plot(x, ys] plt.chow() 11 drax polygon((0, 0), (1, 2), (2, 01) - Kinking lines Wherever you have a line like this, from (xo. yu) to (x1, y1): 11 draw_polygon((0, 01, (1, 01, closed-zalsel You need to add a "kink to it, as follows: I draw_polygon, (0, 0), (0.25, 0), 10.3, 0.25), (0.75, 0), 11, 0), closed=False) Now this kink must be invariant with respect to directions and scaling. For example, if the original line was from up to down: 1 draw polygon (0, 0), (0, -1), Cload-100) + Code + Text Connect - Editing [ draw_polygon (0, 0), 10, -1), closed=False) Then adding the kink will result in: | draw_polygon10, 0), 10, -0.25), (0.25, -0.5), (0, -0.75), (0, -1), closed-False) We call the above operation 'adding a kink". To define it mathematically, we need to use vector addition, so here is a quick reminder. If you have two vectors v = (Ux, wy) and w = (Wx, 60p), their sum z = v + w is computed in componentwise fashion, which you can do in code, like so: VX, Vy-Y XX Vy-V - (VX + xy Vy - wy! With that notation, we can define adding a kink as follows. If you have a segment from point po = (x0: YO) to point p1 = (1, 1), its direction Is A = (x1, 71) (X0 Yo) = (x1 - x0). 1 You) =(4,, 4,), and its perpendicular direction is v = (-4, 4.). The points along the kink are then: go = pu (initial point), Q1 = P + 4 (points where it 'kinks up'); . 92 = pu + 4 +v(tip of the kink): Q3 = put A (points where it kinks back to straight); Pl (final point) The first task for you in implementing fractals is to implement a function kink that, given a segment from po to pi, returns the points 40,41,42, 41. Every point here is represented as a tuple. Note that the last point p. is not returned (this will make it easier to kink a polygon). [ ] def kink(po, pl): """Returns the tuple of the four points q0, gi, 42, 43, resulting from kinking po, pi. Note that each g is as a two-element tuple.'** * YOUR CODE DERE U18 Here you can test your code YOUR CODE HERE [1 * tere you can test your code. # YOUR CODE HERE Let's check that this works for the two cases above. 5 pt assert kinki(0, 0), (1, 0)) == ((0, 0), (0.25, 0.0), (0.5, 0.25), (0.75, 0.0); 2. sert kinki(0, 0), (0, -1)) - ((0, 0), (0.0, -0.25), (0.25, -0.5), (0.0, -0.751) For the general case, let us define an approximate comparison of a list of points. [ det approxeg(listi, list2, epsilon-0.001) assert lerlisti) -- Lerilist2) for pl, p2 in sipilistl, list2): xi, yi = pl x2, y2 = p2 25sert abs(x2 xi) > approxe/kink[/4, 3), 1-9, -1}], ((, 3), (0.75, 2.0), (-1.5, -2.25), (-5.75, 0.01))
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
