Problem 567. Crossing to Kissing - Untangle the Lines
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
-
1 Comment
Technically, L1 & L2 are line segments, and L3 & L4 are polylines.
Solution Comments
Show commentsGroup

Indexing I
- 27 Problems
- 236 Finishers
- Piecewise linear interpolation
- Longest run of consecutive numbers
- Construct an index vector from two input vectors in vectorized fashion
- Getting the indices from a matrix
- First non-zero element in each column
- Return unique values without sorting
- Return a list sorted by number of consecutive occurrences
- intersection of matrices
- Generate N equally spaced intervals between -L and L
- Check if number exists in vector
- Replicate elements in vectors
- We love vectorized solutions. Problem 1 : remove the row average.
- intersection of matrices
- Generate N equally spaced intervals between -L and L
- Create logical matrix with a specific row and column sums
- Return a list sorted by number of consecutive occurrences
- Replicate elements in vectors
- Get the elements of diagonal and antidiagonal for any m-by-n matrix
- Getting the indices from a matrix
- Check if number exists in vector
- Fill a zeros matrix
- Set the array elements whose value is 13 to 0
- Construct an index vector from two input vectors in vectorized fashion
- Joining Ranges
- Remove the two elements next to NaN value
- Reindex a vector
- Longest run of consecutive numbers
- Put two time series onto the same time basis
- Getting logical indexes
- Matrix indexing with two vectors of indices
- middleAsColumn: Return all but first and last element as a column vector
- Return elements unique to either input
- "Low : High - Low : High - Turn around " -- Create a subindices vector
- Return unique values without sorting
- Find the largest value in the 3D matrix
- Specific Element Count
- First non-zero element in each column
Problem Recent Solvers31
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!