Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Starter code: Section 2 : The Line class ( 5 pts ) The Line class represents a 2 D line that stores two Point 2
Starter code: Section : The Line class pts The Line class represents a D line that stores two PointD objects and provides the distance between the two points and the slope of the line using the property methods getDistance and get Slope. The constructor of the PointD class has been provided in the starter code. Methods Type Name float getDistance float getSlope Description Returns the distance between two PointD objects Returns the slope of the line that passes through the two points Special methods Type Name Description str str bool Line repr eq mul Gets a legible representation of the Line in the form yme b Determines if two Line objects are equal Returns a new Line object where each coordinate is multiplied by a positive integer Preconditions: get Distanceself A property method behaves like an attribute that gets the distance between the two PointD objects that created the Line. The formula to calculate the distance between two points in a two dimensional space is: dx xyy y Returns a float rounded to decimals. To round you can use the round method as roundvalue #ofDigits Output float Returns the distance between the two point objects that pass through the Line getSlopeself A property method behaves like an attribute that gets the slope gradient of the Line object. The formula to calculate the slope using two points in a twodimensional space is: yyi m X X Returns a float rounded to decimals. To round you can use the round method as roundvalue #ofDigits Output float Returns the slope of the line, float inf float for undefined slope denominator is zeroSection : The Line class Examples: pl PointD P Point D line Line p p linegetDistance linegetslope str and repr A special method that provides a legible representation for instances of the Line class. Objects will be represented using the "slopeintercept" equation of the line: y mx b To find b substitute m with the slope and y and x for any of the points and solve for b b must be rounded to decimals. To round you can use the round method as roundvalue #ofDigits Output str Slopeintercept equation of the line, representation must be adjusted if mor bare or if b is positive negative Undefined for undefined slope str Examples: P Point D P Point D line Linep p line y x lineLinePoint D Point D lines y x lineLinePointD Point D linegetDistance linegetslope inf line Undefined line LinePoint D PointD line y Section : The Line class eg A special method that determines if two Line objects are equal. For instances of this class, we will define equality as two lines having the same points. To simplify this method, you could try defining equality in the PointD class Output bool True if lines have the same points, False otherwise A special method to support the operator. Returns a new Line object where the xy attributes of every PointD object is multiplied by the integer. The only operations allowed are integerLine and Line" integer, any other noninteger values return None. You will need to override both the "normal" version and the "right side" version to support such operations. Output Line A new Line object where pointl and point are multiplied by an integer Examples: p PointD P Point D line Line p p line line isinstanceline Line True line y x lineline line y x lineline False lineline True line Falseclass Line: p Point D p Point D line Line p p linegetDistance linegets lope line y x line line linegetDistance linegetslope line y x line y x line line line y x lineline False lineline True lineLinePoint D Point D line y x line False lineLinePoint D Point D line.getDistance line gets lope inf line Undefined line LinePoint D Point D line getslope line y def initself pointi, point: # YOUR CODE STARTS HERE pass # YOUR CODE STARTS HERE def getDistanceself: pass # YOUR CODE STARTS HERE def getslopeself: pass # YOUR CODE CONTINUES HERE
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started