-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInterpolation.java
48 lines (40 loc) · 1.57 KB
/
Interpolation.java
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
package com.wtv.processing;
import java.util.concurrent.TimeUnit;
public class Interpolation {
public static void main(String[] args) {
compare(2,3, 2);
}
public static void compare(double v0, double v1, double x){
System.out.println(String.format("Input: %s, %s, %s", v0, v1, x));
System.out.println("Continue: " + linInterpolContinue(v0,v1,x));
System.out.println("FixInterval: " + linInterpolFixInterval(v0,v1,x));
System.out.println("DefZero: " + linInterpolDefZero(v0,v1,x));
try {
System.out.println("Err: " + linInterpolErr(v0,v1,x));
} catch (IllegalArgumentException e){
System.out.println("Err: ");
e.printStackTrace();
try {
TimeUnit.MILLISECONDS.sleep(500);
} catch (InterruptedException interruptedException) {
interruptedException.printStackTrace();
}
}
}
public static double linInterpolContinue(double v0, double v1, double x){
return ((v1 - v0) * x) + v0;
}
public static double linInterpolFixInterval(double v0, double v1, double x){
if(x < 0) return v0;
if(x > 1) return v1;
return ((v1 - v0) * x) + v0;
}
public static double linInterpolDefZero(double v0, double v1, double x) {
if (0 > x || x > 1) return 0;
return ((v1 - v0) * x) + v0;
}
public static double linInterpolErr(double v0, double v1, double x) {
if (0 > x || x > 1) throw new IllegalArgumentException();
return ((v1 - v0) * x) + v0;
}
}