Question: 4. Implement lines.py In this problem, you will write functions to characterize lines and find the point of intersection of two lines if it exists.

4. Implement lines.py

In this problem, you will write functions to characterize lines and find the point of intersection of two lines if it exists. Let's consider a two-dimensional space. Given two lines:

=1+1y=m1x+b1

=2+2y=m2x+b2

three possibilities may arise:

The two lines are the same i.e. they are coincident

The two lines are parallel

The two lines intersect at a unique point

All the necessary mathematical background you may need is provided below.

4a. Parallel Lines (3 points)

The two lines are parallel if 1=2m1=m2 and 12b1=b2.

Your task is to implement a function with the following signature:

def are_parallel(m1:float, b1:float, m2:float, b2:float) -> bool 

The function take as argument four floats m1, m2, b1, b2 as described above and returns whether the two lines defined by the specified parameters are parallel or not.

Example:

are_parallel(0.75, 1, 0.75, 2) # This should return True are_parallel(1, 2.5, 3.5, 2.5) # This should return False 

4b. Coincident Lines (3 points)

The two lines are the same (coincident) if 1=2m1=m2 and 1=2b1=b2.

Your task is to implement a function with the following signature:

def are_same(m1:float, b1:float, m2:float, b2:float) -> bool 

The function take as argument four floats m1, m2, b1, b2 as described above and returns whether the two lines defined by the specified parameters are coincident or not.

Example:

are_same(0.75, 1, 0.75, 1) # This should return True are_same(0.75, 1, 0.75, 2) # This should return False 

4c. Lines with Unique Intersection (3 points)

The two lines intersect at a unique point if 12m1=m2.

Your task is to implement a function with the following signature:

def have_unique_intersection(m1:float, b1:float, m2:float, b2:float) -> bool 

The function take as argument four floats m1, m2, b1, b2 as described above and returns whether the two lines defined by the specified parameters intersect at a unique point or not.

Example:

have_unique_intersection(1, 2.5, 3.5, 2.5) # This should return True have_unique_intersection(0.75, 2, 0.75, 4) # This should return False have_unique_intersection(0.75, 2, 0.75, 2) # This should return False 

4d. Intersecting Lines (3 points)

Two lines are said to intersect either if they have a unique intersection point or they are coincident.

Your task is to implement a function with the following signature:

def have_intersection(m1:float, b1:float, m2:float, b2:float) -> bool 

The function take as argument four floats m1, m2, b1, b2 as described above and returns whether the two lines defined by the specified parameters intersect or not.

Example:

have_intersection(1, 2.5, 3.5, 2.5) # This should return True have_intersection(0.75, 1, 0.75, 1) # This should return True have_intersection(0.75, 2, 0.75, 4) # This should return False 

4e. Point of intersection

For two lines that have a unique intersecting point, we can easily determine this point. Since we are working with lines in a two dimensional plane, this point is an ordered pair of the form (,)(x,y).

Part I: Determining the x coordinate (3 points)

A well established result states that =(12)12x=m1m2(b1b2).

Your task is to implement a function with the following signature:

def x_intersect(m1:float, b1:float, m2:float, b2:float) -> float 

The function takes as arguments four floats m1, m2, b1, b2 as described above and returns the x-coordinate of the point of intersection. The function should only return an output if the lines specified have a unique point of intersection, otherwise give an error.

Hint: For the error, use an assert statement with one of the functions 4a. - 4d.

Example:

x_intersect(1, 2.5, 3.5, 2.5) # This should return 0 x_intersect(3.5, 2.5, 3.5, 7.5) # This should give an ERROR! x_intersect(3.5, 2.5, 3.5, 2.5) # This should give an ERROR! 

Part II: Determining the y coordinate (3 points)

Notice that once we determine x, we can use direct substitution into the equations of the lines to calculate y. Therefore, given x, we can calculate y as either of the following:

=1+1y=m1x+b1

=2+2y=m2x+b2

Your task is to implement a function with the following signature:

def y_intersect(m1:float, b1:float, m2:float, b2:float) -> float 

The function takes as arguments four floats m1, m2, b1, b2 as described above and returns the y-coordinate of the point of intersection. The function should evaluate y using the two equations specified above, verify that both the equations yield the same value of y and return an output if the lines specified have a unique point of intersection, otherwise give an error.

Hint: For the error, use an assert statement with one of the functions 4a. - 4d.

Example:

y_intersect(1, 2.5, 3.5, 2.5) # This should return 2.5 y_intersect(3.5, 2.5, 3.5, 7.5) # This should give an ERROR! y_intersect(3.5, 2.5, 3.5, 2.5) # This should give an ERROR!

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!