python intersection lines

def line_intersection(line1, line2):
    xdiff = (line1[0][0] - line1[1][0], line2[0][0] - line2[1][0])
    ydiff = (line1[0][1] - line1[1][1], line2[0][1] - line2[1][1])

    def det(a, b):
        return a[0] * b[1] - a[1] * b[0]

    div = det(xdiff, ydiff)
    if div == 0:
       raise Exception('lines do not intersect')

    d = (det(*line1), det(*line2))
    x = det(d, xdiff) / div
    y = det(d, ydiff) / div
    return x, y

print (line_intersection((A, B), (C, D)))

# And FYI, I would use tuples instead of lists for your points. E.g.
# A = (X, Y)

Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
line intersection formula python find intersection of line and box python python get intersection of two lines python how to find the intersection of two lines intersection of two line python python line intersection algorithm code to find intersection of two lines python python find line intersection find intersection of point with line python two line intersection python line intersection in python nymbi point of intersection of two lines python line intersection points python program to determine the intersection point of two line python simple p python program to determine the intersection point of two line. how to find intersection of two lines in python python find intersection between two lines python area intersect four vertices python area intersect four points python four points intersect how to find where two lines intersect python line line intersection python how to find intersection of two lines trigonometry python catch line intersection python how to create four points based on intersections of two python calculate intersection of two lines python calculate lines intersection using equation of the line python How do I compute the intersection point of two lines python python function to find the intersection of two lines find intersection between two line python intersect two lines python get intersection of two lines python lines intersection python detect line intersection python determine when two lines cross python finding the intersection point of two lines pytho find intersection of two lines with four points python intersectionf a lines in python intersection of lines in python python find intersection between lines problem python find intersection between lines python intersection of two lines givren lines how to find the intersetion points in python line intersection algorithm python python find intersection between two line python to find intersection line python to detect and find intersection of two lines find point of intersection of two lines python find intersection of two lines python intersection of line python find where two lines intersect python Cutting point between functions python python intersection of two line segments when two lines intersect length python line intersection python python line intersection line intersection point in python line intersection in python python code to find line intersection python find intersection of two lines intersection of two lines in python python intersection lines
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source