Answered step by step
Verified Expert Solution
Question
1 Approved Answer
import math class Point 2 D: def _ _ init _ _ ( self , x , y ) : self.x = x self.y =
import math
class PointD:
def initself x y:
self.x x
self.y y
class Line:
def initself point point:
self.p point
self.p point
pass
def getDistanceself:
# YOUR CODE CONTINUES HERE
def getSlopeself:
# YOUR CODE CONTINUES HERE
def strself:
# YOUR CODE CONTINUES HERE
reprstr
def mulselfother:
# YOUR CODE CONTINUES HERE
def containsselfpoint:
# YOUR CODE CONTINUES HERE
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 getSlope. The constructor of the PointD class has been provided in the starter code. You might use the math module
getDistanceself
A property method that gets the distance between the two PointD objects that created the Line. The formula to calculate the distance between two points in a twodimensional space is:
Returns a float rounded to decimals. To round you can use the round method as roundvalue
#ofDigits
getSlopeself
A property method that gets the slope gradient of the Line object. The formula to calculate the slope using two points in a twodimensional space is:
If the slope exists, returns a float rounded to decimals, otherwise, returns infinity as a float inf float To round you can use the round method as roundvalue #ofDigits
Examples:
p PointD
p PointD
line Linep p
linegetDistance
linegetSlope
strself and reprself
Special methods that provide 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 The representation will be the string Undefined if the slope of the line is undefined. You are allowed to define a property method to compute the interception b Note that the representation must account for all ranges of values for m and b: y b when x y mx b when b is negative, etc.
Examples:
p PointD
p PointD
line Linep p
line
y x
lineLinePointDPointD
line
y x
lineLinePointD PointD
linegetDistance
linegetSlope inf line
Undefined
lineLinePointD PointD
line y
mul
A special method to support the operator. Returns a new Line object where the xy attributes of every PointD object is multiplied by an integer. The only operation allowed is Lineinteger any other noninteger values return None.
contains
A special method to support the in operator. Returns True if the Point object lies on the Line object, False otherwise. You cannot make any assumptions about the value that will be on the right side of the operator. If the slope is undefined, return False.
Examples:
p PointD
p PointD
line Linep p
line line
isinstanceline Line
True line y x
line line
line
y x
lineLinePointDPointD
line
y x
PointD in line
False
PointD in line
True
in line
False
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