-1

What if I have 2 line segments that is defined by two starting and ending points such as below:

line segment 1 starts [0,0] and ends at [5,0] another line segment 2 starts at [3,0] and ends at [8,0]

How do I check that line segment 2 extends out of line segment 2 and also if the two line segments aren't necessarily horizontal nor vertical but at a slope? Is there a generalized code for that? Thank you in advance.

Mahmoud Ayman
  • 197
  • 1
  • 13

1 Answers1

0

Use scipy linear regressions to save yourself some pretty obvious but lengthy code:

x1 = np.array([0, 5])
y1 = np.array([0, 0])

x2 = np.array([3, 0])
y2 = np.array([8, 0])

data1 = scipy.stats.linregress(x1, y1)
data2 = scipy.stats.linregress(x2, y2)

m1, b1 = data1[:2] # slope and intercept of 1st line
m2, b2 = data2[:2] # slope and intercept of 2nd line

if m1 == m2 and b1 == b2:
    print 'These are extensions'
Malik Brahimi
  • 16,341
  • 7
  • 39
  • 70