Computer Science

IT Matura Course | Algorithms #21


categories: computer science

Welcome,
Below you will find a video with a detailed explanation of the algorithm for checking whether two line segments intersect. Its operation, time complexity, and usefulness. Below you will also find ready-to-use code that you can copy if needed.
Code:


def czyPrzecinaja(punkt1, punkt2, punkt3, punkt4):
    if punkt1 == punkt3 or punkt1 == punkt4 or punkt2 == punkt3 or punkt2 == punkt4:
        return True
    else:
        a = (punkt2[1] - punkt1[1]) / (punkt2[0] - punkt1[0])
        b = punkt1[1] - (a * punkt1[0])
        
        if a * punkt3[0] + b >= punkt3[1] and a * punkt4[0] + b <= punkt4[1]:
            return True
        elif a * punkt3[0] + b <= punkt3[1] and a * punkt4[0] + b >= punkt4[1]:
            return True

    return False

print(czyPrzecinaja([1, 2], [6, 12], [1, 8], [6, 0]))
                  

Video:

Thank you for reading!


Read more
Administrator

This post was written by the administrator

Recent Posts

Proof Problems in Mathematics The Beginning Integrals, Course Practical Physics for Engineers IT Matura Course | Algorithms IT Matura Course | Databases IT Matura Course | Theory IT Matura Course | Spreadsheet

Archive

Year 2022

Comments