Detect if a 2D line is inside another 2D line

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Yeldham

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
:bust_in_silhouette: Reply From: rustyStriker

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.