Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Split line into multiple line

Tags:

geometry

line

I have a one line. For this line I have start and end point. Now I want to split this line into multiple lines or number of points. How to do that?

The line looks likes below ..

enter image description here

Any idea?

like image 939
Shiladittya Chakraborty Avatar asked Sep 19 '15 03:09

Shiladittya Chakraborty


People also ask

How do I split a string into multiple lines?

You can have a string split across multiple lines by enclosing it in triple quotes. Alternatively, brackets can also be used to spread a string into different lines. Moreover, backslash works as a line continuation character in Python. You can use it to join text on separate lines and create a multiline string.

How do I split a row into multiple lines in a cell?

Click in a cell, or select multiple cells that you want to split. Under Table Tools, on the Layout tab, in the Merge group, click Split Cells. Enter the number of columns or rows that you want to split the selected cells into.

How do you split a single line into multiple lines in Unix?

To split long commands into readable commands that span multiple lines, we need to use the backslash character (\). The backslash character instructs bash to read the commands that follow line by line until it encounters an EOL.


1 Answers

Python solution:

def split(start, end, segments):
    x_delta = (end[0] - start[0]) / float(segments)
    y_delta = (end[1] - start[1]) / float(segments)
    points = []
    for i in range(1, segments):
        points.append([start[0] + i * x_delta, start[1] + i * y_delta])
    return [start] + points + [end]

print split([-10, 20], [20, 75], 5)

Output:

[[-10, 20], [-4.0, 31.0], [2.0, 42.0], [8.0, 53.0], [14.0, 64.0], [20, 75]]
like image 105
Jason Avatar answered Oct 14 '22 12:10

Jason