-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCollinearity
More file actions
24 lines (11 loc) · 884 Bytes
/
Collinearity
File metadata and controls
24 lines (11 loc) · 884 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/*
Theoretical Material
You are given two vectors starting from the origin (x=0, y=0) with coordinates (x1,y1) and (x2,y2). Your task is to find out if these vectors are collinear. Collinear vectors are vectors that lie on the same straight line. They can be directed in the same or opposite directions. One vector can be obtained from another by multiplying it by a certain number. In terms of coordinates, vectors (x1, y1) and (x2, y2) are collinear if (x1, y1) = (k*x2, k*y2) , where k is any number acting as a coefficient.
For more information, check out this article on collinearity.
Problem Description
Write the function collinearity(x1, y1, x2, y2), which returns a Boolean type depending on whether the vectors are collinear or not.
all coordinates are integers
-1000 <= any coordinate <= 1000
*/
def collinearity(x1, y1, x2, y2):
return (x1*y2) == (x2*y1)