Question: Write a class named Point that has two data members, x _ coord and y _ coord, representing the two coordinates of the point. It
Write a class named Point that has two data members, xcoord and ycoord, representing the two coordinates of the point. It should have:
an init method that takes two arguments, an xcoordinate and ycoordinate in that order and uses them to initialize the two data members.
get methods for the two data members: getxcoord and getycoord.
a method named distanceto that takes a Point object as an argument. It returns the distance between the Point object the method is called on the one in front of the dot and the Point object passed as the argument. For example, if point and point are both Point objects, then pointdistancetopoint should return the distance between point and pointand pointdistancetopoint should return the same distance For this method, you'll calculate the distance using the following formula:
formula for distance between two points where d is the distance and the two points are x y and x y
The above formula requires taking the square root. As you might recall from Project c you can do by just using an exponent of For example, the result of would be Python does have a specific sqrt function, but that involves importing a module, which we haven't covered yet.
Now write a class named LineSegment that has two data members, endpoint and endpoint representing the two endpoints of the line segment. It should have:
an init method that takes two Point objects as arguments and uses them to initialize the two data members the endpoints of the LineSegment
get methods for the two data members: getendpoint and getendpoint
a method named length that takes no arguments and returns the distance between its two endpoints. This can make use of the Point's distanceto method.
a method named slope that takes no arguments and returns the slope of the LineSegment. You can find the slope using the following formula:
formula for slope of a line segment where m is the slope and again the two points are x y and x y which in this case are the two endpoints of the LineSegment.
a method named isparallelto that takes a LineSegment object as an argument. It returns True a Boolean value, not a string if the LineSegment the method is being called on is parallel to the one being passed as the argument. Otherwise, it should return False. For example, if lineseg and lineseg are both LineSegment objects, then linesegisparalleltolineseg should return True if those two line segments are parallel, but otherwise should return False. For this method, you'll calculate the slopes of the two LineSegments and compare them. If the two slopes are equal, then the two line segments are parallel, otherwise they are not. This can make use of the slope method. Remember that you shouldn't test two floats for exact equality because of possible lack of precision or roundoff errors. Instead, if you need to compare float values for equality, you can do it like this: absnum numewhich uses scientific notation to represent a very small number
Here's a simple example of how your code might be used:
point Point
point Point
printpointdistancetopoint
lineseg LineSegmentpointpoint
printlineseglength
printlinesegslope
point Point
point Point
lineseg LineSegmentpointpoint
printlinesegisparalleltolineseg
Hint : Remember the difference between a class and an object. The class is just a blueprint for making objects. For example, don't try to ask the Point class for coordinates. It doesn't have any coordinates of its own and it doesn't know anything about any Point objects you may have created.
Hint : Start with the Point class and make sure it's working correctly before going on to the LineSegment class.
Hint : In the distanceto method, you'll be working with two pairs of coordinates. The Point object the method is called on is the one that executes the method, and it can access its own coordinates directly, for example self.xcoord. The other pair of coordinates comes from the Point that was passed in as an argument. Because the distanceto method belongs to the Point class, it can access those Point data members directly, without needing to use a get method. For example, if the parameter name is otherpoint, you can do otherpoint.xcoord.
Hint : In the methods of t
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
