deno.land / x / masx200_leetcode_test@10.6.5 / max-points-on-a-line / calculateStraightLineEquation.ts

calculateStraightLineEquation.ts
نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
export function calculateStraightLineEquation( point1: number[], point2: number[],): [number, number, number] { const [x1, y1] = point1; const [x2, y2] = point2; let a = 0; let b = 0; let c = 0; if (x1 === x2) { /* x=x1; 1x-x1=0 a=1 c=-x1 */ a = 1; c = -x1; } else if (y1 === y2) { b = 1; c = -y1; } else { /* ax1+by1+c=0 ax2+by2+c=0
a(x1-x2)+b(y1-y2)=0 a(x1-x2)=b(y2-y1) a=y2-y1 b=x1-x2 */ a = y2 - y1; b = x1 - x2; /* c=-ax1-by1 (y2-y1)x1+(x1-x2)y1+c=0 c=-(y2-y1)x1-(x1-x2)y1 */ c = -a * x1 - b * y1; } return [a, b, c];}
masx200_leetcode_test

Version Info

Tagged at
a year ago