Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using python write the code 1 import math 2 epsilonle-5 A Point Class Definitionn A two-dimensional point may be represented by an x- and y-coordinate.

Using python write the code

image text in transcribed

1 import math 2 epsilonle-5 A Point Class Definitionn 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. 5 class Point (object): "A 2D point in the cartesian plane"" definit (self, x, y) We have provided an init__definition for the Point class. You will note that this accepts two arguments, being the x- and y-coordinates of the point. 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 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_repr could be copied into the interpreter in order to create an identical point. This is a characteristic of most good_ repr_methods. self. x - x self"-y-y def repr(self): 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.sqrt. 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, 1e-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 self

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practical Database Programming With Visual C# .NET

Authors: Ying Bai

1st Edition

0470467274, 978-0470467275

More Books

Students also viewed these Databases questions

Question

2. What do you believe is at the root of the problem?

Answered: 1 week ago