Coding Math: Episode 33 - Line Intersections Part II

preview_player
Показать описание
Today we deal with parallel and collinear lines and line segment intersections.

Рекомендации по теме
Комментарии
Автор

I just utilized the utils.inRange function and all worked fine, Code given below:

var intersectX = (C1 * B2 - C2 * B1) / denominator,
intersectY = (C2 * A1 - C1 * A2) / denominator;
if(utils.inRange(intersectX, p0.x, p1.x) && utils.inRange(intersectY, p0.y, p1.y) &&
utils.inRange(intersectX, p2.x, p3.x) && utils.inRange(intersectY, p2.y, p3.y)){
return {
x: intersectX,
y: intersectY
}
}

And thanks for all these great tutorials!

orainrobert
Автор

You saved my Bachelor of Science program. BIG THANKS!!!!

RadHimself
Автор

I saw this when I was in class today and am so glad I finally get to watch it! Thanks as always!

Polaroidon
Автор

I was working on a program that solves the Travelling Salesman Problem. I needed a function to check if two paths cross so I could reduce redundancy. This would have been perfect.

kevnar
Автор

Hey! Could you do an episode on intersections with Bézier curves?

BinaryHistory
Автор

There watched your video library in 2 days. Damn cool all of it.(wrestled with rewriting tween functions to C# to use in Unity for simple animations(>Lerp, <Mecanim), about 4-6 months ago, nice to know how that actually works)

jim_o
Автор

if(inRange(intersectX, p0.x, p1.x) && inRange(intersectX, p2.x, p3.x))
return {x: intersectX,
y: intersectY
};
else
return null;
I use this code to check if the intersection point is in two segment lines. It look simpler :D

quanglien
Автор

Very nice and clear videos indeed. I was wondering why not to use the inRange function defined in Episode 14 to check the line segment intersection. It should save some costly divisions. This would additionally allow segmentIntersect to call lineIntersect honoring the DRY principle.

IlariVallivaara
Автор

For checking if the lines are parallel, why look at the denominator, when you can just compare slope values?

origedit
Автор

Hello, this 3 part series was super helpfull for me and I know it's 3 years old,
but i've noticed that there is a bug with segment intersection when i'm comparing 2 perpendicular lines (100, 500) - (500, 500) and (50, 200)-(150, 200) it doesn't find an intersect point.
I've narrowed it down to the ratio logic.

anud
Автор

I translated this code to C# but it seems to fail. I used the following test data:

p0: (0, 0) p1(0, 1) p2(13, 9) p3(22, 9)

Gives intersecting point of: (0, 9)

In C# vectors use floats (i am not sure what javascript uses, but one would assume floats or doubles).

So could this be a float precision issue, it seems unlikely since the intersection is very far away even for precision issues.


Did i make any errors? I am using the X:Z plane but that shouldn't matter.

WelshGuitarDude
Автор

thanks! good explanation but it fail for me with two perpendicular segment !!! ry0 always return NAN

rrastakongrrastakong
Автор

I am gonna make a missile command clone with this...

acatisfinetoo