In python LiLiOblique (L1, L2) Write the function LiLiOblique that takes two obl
ID: 3750059 • Letter: I
Question
In python
LiLiOblique (L1, L2) Write the function LiLiOblique that takes two oblique lines in 2-space, L1 and L2, and returns their point of intersection.
Two lines are oblique if they are not parallel and not orthogonal. We will actually test your code against lines that are quite oblique: the angle between the two lines is between 10 and 80 degrees. Using two oblique lines guarantees a finite intersection. Two parallel lines do intersect, but at infinity, so parallel lines require subtle treatment in code, and avoiding them simplifies your code. This is a useful idea for code development: solve a simpler special case first, then generalize once your code is perfected on the special case.
Each line is represented by two points on the line, so L1 and L2 are float 4-tuples.
The background necessary to solve this question is given on the next page.
In hw3.py, I have provided stubbed helper functions that are necessary to solve LiLiOblique. For example, PPtoPV translates from the 2-point representation of a line to the point-vector representation. Remember that a major purpose of this homework is to learn the principle of divide and conquer, by working with it firsthand and discovering how it simplifies a problem.
Once you have coded the problem, you may visualize your answer using vizLiLi.py, which randomly chooses some oblique lines, computes all of their intersections, and draws them. This should help you polish your code. You may want to change the number of lines to 2 at the bottom of the code as you start debugging.
Intersection is a fundamental problem in computer graphics (e.g., shape modeling, ray casting, lighting, visibility), computer vision (e.g., multiple view geometry), robotics (e.g., motion planning, collision detection), and many other disciplines. Essentially, any geometric code will eventually need intersection. To illusrate this point, the principles on the following page are included in an appendix of a classic book on computer graphics by Newman and Sproull. (Feel free to give it a look.) You may be interested to know that there is an entire area of mathematics (algebraic geometry) dedicated almost exclusively to the understanding of intersection.
Explanation / Answer
here is your program : ------------------>>>>>>>>
def LiLiOblique(L1,L2):
m1 = ((float(L1[3])-float(L1[1]))/(float(L1[2])-float(L1[0])))
m2 = ((float(L2[3])-float(L2[1]))/(float(L2[2])-float(L2[0])))
if m1 == m2:
print("Parallel Lines")
return (None,None)
c1 = float(L1[1]) - (m1*float(L1[0]))
c2 = float(L2[1]) - (m2*float(L2[0]))
x = (c2 - c1)/(m1 - m2)
y = float(m1*x + c1)
return (x,y)
print(LiLiOblique([0,50,4,130],[0,30,4,150]))
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.