-
Notifications
You must be signed in to change notification settings - Fork 0
/
linear_interpolation.a68
67 lines (50 loc) · 1.32 KB
/
linear_interpolation.a68
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
PROC lerp = ([] INT row one, [] INT row two, INT point x) INT:
BEGIN
CO
Linear interpolation in Algol 68
CO
IF ELEMS row one /= 2 OR ELEMS row two /= 2
THEN
stop
FI;
INT x one = row one [1];
INT x two = row two [1];
INT y one = row one [2];
INT y two = row two [2];
INT uknown y = y one + ((point x - x one)*((y two - y one) % (x two - x one)));
uknown y
END;
BEGIN
CO
Y
*
* 700
*-------------------*
* |
* 500 |
*-----* |
* | ? |
* | |
* | |
* | |
* | |
**************************X
| | |
2018 2020 2024
CO
print(("X 1?", new line));
INT x one = read int;
print(("Y 1?", new line));
INT y one = read int;
print(("X 2?", new line));
INT x two = read int;
print(("Y 2?", new line));
INT y two = read int;
print(("X?", new line));
INT uknown x = read int;
[] INT row one = (x one, y one);
[] INT row two = (x two, y two);
INT point = uknown x;
INT uknown := lerp(row one, row two, point);
print((uknown, new line))
END