Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def slope(x1, y1, x2, y2):
- '''calculate a in formula y=a*x+b'''
- dx = (x2 - x1)
- dy = (y2 - y1)
- a = 0
- b = 0
- if dx != 0:
- a = dy/dx # slope (tangens)
- #b = y1 - a*x1 # or b = y2 - a*x2
- #print(b)
- return a
- slope1 = slope(0, 1, 1, 2) # first line
- slope2 = slope(0, 0, 1, 1) # second line
- print('Slopes to y=0:', slope1, slope2)
- print('Collinear:', slope1 == slope2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement