SHARE
TWEET

Python - slope and collinear

furas Jun 26th, 2018 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top