Advertisement
furas

Python - slope and collinear

Jun 26th, 2018
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.44 KB | None | 0 0
  1. def slope(x1, y1, x2, y2):
  2.     '''calculate a in formula y=a*x+b'''
  3.  
  4.     dx = (x2 - x1)
  5.     dy = (y2 - y1)
  6.    
  7.     a = 0
  8.     b = 0
  9.    
  10.     if dx != 0:
  11.         a = dy/dx # slope (tangens)
  12.    
  13.     #b = y1 - a*x1 # or b = y2 - a*x2
  14.     #print(b)
  15.    
  16.     return a
  17.  
  18. slope1 = slope(0, 1, 1, 2) # first line
  19. slope2 = slope(0, 0, 1, 1) # second line
  20.  
  21. print('Slopes to y=0:', slope1, slope2)
  22. print('Collinear:', slope1 == slope2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement