Question: Using python... write codes.. for each pic A Point Class Definition A two-dimensional point may be represented by an x- and y-coordinate. In this problem,

Using python... write codes.. for each pic

A Point Class Definition

A two-dimensional point may be represented by an x- and y-coordinate. In this problem, you will write a Point class which stores this information and provides useful methods to work with points.

Using python... write codes.. for each pic A Point Class Definition A

Define the class Rectangle. Its constructor takes a pair of numbers representing the top-left corner, and two other numbers representing the width and height. It has the following methods:

two-dimensional point may be represented by an x- and y-coordinate. In this

import math 2 epsilon = 1e-5 We have provided an init definition for the Point class. You will note that this accepts two arguments, being thex- and y-coordinates of the point. 5 class Point (object): A 2D point in the cartesian plane" def init (self, x, v) We have also included a repr method, which will provide a canonical string representation of the point. Make sure you don't change this method, as we will use it for some tests. Note that the output of repi could be copied into the interpreter in order to create an identical point. This is a characteristic of most good repr methods. Construct a point object given the x and y coordinates 10 Parameters: x (float): x coordinate in the 2D cartesian plane y (float) y coordinate in the 2D cartesian plane 12 13 14 15 16 17 18 19 20 21 The first thing our Point class should be able to do is determine the distance between points. Write a method dist to point, which accepts another instance of the Point class as an argument, and returns the Euclidean distance between the two points. It may be helpful to use math.sgrt. self. xx self._y-Y def epr(self): return 'Point(,".format (self. x, self._y) Using dist_ to_ point, now write a method is_near which returns whether two points are close. Remember that you can call other methods in a method definition using self, eg self.other method(arg) A point is considered 'close, if it is within epsilon of another point. We defined epsilon to be a really small number using scientific notation (so, eg le-3 IS 1x10-3 IS 0.001 Finally, we want to be able to add two points together. Write a method add point that adds the position of the Point object given as an argument to the position of sel:f

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!