Turn lines that cross into lines that kiss.
You will be given two lines that cross at some point. Your job is to untangle them in the following way. Imagine two line segments, L1 and L2. L1 goes from (0,0) to (2,2). L2 goes from (0,1) to (2,1). We can specify them like so.
L1 = [0 0;
2 2] L2 = [0 1;
2 1]We want to transform these into two non-crossing segmented lines that look the same when plotted. To do this, we need to introduce a new point in each line. Both lines share this point, so now they "kiss" instead of crossing.
L3 = [0 0;
1 1;
2 1] L4 = [0 1;
1 1;
2 2] * L1 * L4
/ /
/ /
L2 *--/--* L2 L4 *--*--* L3
/ /
/ /
L1 * L3 *Your function should take the form
[L3,L4] = cross2kiss(L1,L2)
The lines L3 and L4 should be ordered by the y coordinate of their first point. So in the case above, the first point in L3 is [0 0], so it comes first.
Solution Stats
Problem Comments
Solution Comments
Show commentsProblem Recent Solvers34
Suggested Problems
-
Read a column of numbers and interpolate missing data
2351 Solvers
-
Project Euler: Problem 1, Multiples of 3 and 5
3680 Solvers
-
Back to basics 16 - byte order
201 Solvers
-
661 Solvers
-
Calculate the height of an object dropped from the sky
320 Solvers
More from this Author54
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
Technically, L1 & L2 are line segments, and L3 & L4 are polylines.