Cody

Problem 1720. Do the lines intersect?

You are given two line segments. Do they cross?

Consider one segment as (x1,y1) to (x2,y2), the other segment as (x3,y3) to (x4,y4). You are given a = [x1 y1; x2 y2]; b = [x3 y3; x4 y4]. Return tf=true if a and b intersect or tf=false if a and b do not touch.

All lines will intersect cleanly at exactly one non-endpoint. That is, they will not nest, overlap, or "kiss" at the endpoints.

Examples

 a = [0,0; 1,1];
 b = [0,1; 1,0];
 tf = true
 a = [0,0; 1,0];
 b = [0,1; 1,1];
 tf = false

Solution Stats

62.0% Correct | 38.0% Incorrect
Last solution submitted on Mar 12, 2016

Problem Comments

Solution Comments

Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!

Join the 15-year community celebration.

Play games and win prizes!

Learn more