furas

Python - slope and collinear

Jun 26th, 2018
124
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

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×