0 votes

And here I'm again making math questions.

Currently (thanks to Zylann), I have a function that detects if a 2D line intersects with another. It works, with the exception of one situation: If the line is inside another while having the same angle (e. g. (0, 0), (0, 100), (0, 50), (0, 150)), it will not treat it as an intersection.

Here is the current code:

func are_lines_intersecting(a, b, c, d):
    var cd = d - c
    var ab = b - a
    var div = cd.y * ab.x - cd.x * ab.y
    if abs(div) > 0.001:
        var ac = a - c
        var ua = ((cd.x * ac.y) - (cd.y * ac.x)) / div
        if not ua >= 0.0 or not ua <= 1.0:
            return false
        var ub = ((ab.x * ac.y) - (ab.y * ac.x)) / div
        if ub >= 0.0 and ub <= 1.0:
            return true

    return false
in Engine by (81 points)

1 Answer

0 votes

if 2 lines are in one another and are parallel you need a different equation, but i got rid of my math textbook so this is from memory: you need to check if they got the same angle(aka parallel) and if they are parallel you need to check for a specific point on the line(there is a name for this type of point but i cant remember it sorry)...

overall check for analytical geometry, since this is the subject you are working on right now, you might find what i cant remember.

by (1,200 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.