1 – This works AFAIK
, I tried to keep to the style of the interpolateLinear functions. If the scale is less than or equal to 1 then the function will let interpolateLinear() handle it. But if the scale is greater than 1 then my functions will process it. So for example if there were 2 points (1 and 2), with a scale of 0.5, it would return 1.5. With a scale of 1.0, it returns 2, and a scale of 1.5 it returns 2.5, etc
public static float extrapolateLinear(float scale, float startValue, float endValue) {
if(scale <= 0f) {
return startValue;
}
return ((1f - scale) * startValue) + (scale * endValue);
}
public static Vector3f extrapolateLinear(float scale, Vector3f startValue, Vector3f endValue, Vector3f store) {
if (store == null) {
store = new Vector3f();
}
if(scale <= 1f) {
return interpolateLinear(scale, startValue, endValue, store);
}
store.x = extrapolateLinear(scale, startValue.x, endValue.x);
store.y = extrapolateLinear(scale, startValue.y, endValue.y);
store.z = extrapolateLinear(scale, startValue.z, endValue.z);
return store;
}
public static Vector3f extrapolateLinear(float scale, Vector3f startValue, Vector3f endValue) {
return extrapolateLinear(scale, startValue, endValue, null);
}
Edit: Sorry i should probably have shown a test of it, here:
public static void main(String[] args) {
System.out.println("Using extrapolateLinear(scale, new Vector3f(-2,-2,-2), new Vector3f(2,2,2)))");
System.out.println("0f " + extrapolateLinear(0.0f, new Vector3f(-2,-2,-2), new Vector3f(2,2,2)));
System.out.println("0.5f " + extrapolateLinear(0.5f, new Vector3f(-2,-2,-2), new Vector3f(2,2,2)));
System.out.println("1.0f " +extrapolateLinear(1.0f, new Vector3f(-2,-2,-2), new Vector3f(2,2,2)));
System.out.println("1.5f " +extrapolateLinear(1.5f, new Vector3f(-2,-2,-2), new Vector3f(2,2,2)));
System.out.println("nUsing extrapolateLinear(scale, new Vector3f(1,1,1), new Vector3f(2,2,2)))");
System.out.println("0f " +extrapolateLinear(0.0f, new Vector3f(1,1,1), new Vector3f(2,2,2)));
System.out.println("0.5f " +extrapolateLinear(0.5f, new Vector3f(1,1,1), new Vector3f(2,2,2)));
System.out.println("1.0f " + extrapolateLinear(1f, new Vector3f(1,1,1), new Vector3f(2,2,2)));
System.out.println("1.5f " +extrapolateLinear(1.5f, new Vector3f(1,1,1), new Vector3f(2,2,2)));
System.out.println("nUsing extrapolateLinear(scale, new Vector3f(1,2,3), new Vector3f(2,4,6)))");
System.out.println("0f " +extrapolateLinear(0.0f, new Vector3f(1,2,3), new Vector3f(2,4,6)));
System.out.println("0.5f " +extrapolateLinear(0.5f, new Vector3f(1,2,3), new Vector3f(2,4,6)));
System.out.println("1.0f " + extrapolateLinear(1f, new Vector3f(1,2,3), new Vector3f(2,4,6)));
System.out.println("1.5f " +extrapolateLinear(1.5f, new Vector3f(1,2,3), new Vector3f(2,4,6))); }
and the results are:
Using extrapolateLinear(scale, new Vector3f(-2,-2,-2), new Vector3f(2,2,2)))
0f (-2.0, -2.0, -2.0)
0.5f (0.0, 0.0, 0.0)
1.0f (2.0, 2.0, 2.0)
1.5f (4.0, 4.0, 4.0)
Using extrapolateLinear(scale, new Vector3f(1,1,1), new Vector3f(2,2,2)))
0f (1.0, 1.0, 1.0)
0.5f (1.5, 1.5, 1.5)
1.0f (2.0, 2.0, 2.0)
1.5f (2.5, 2.5, 2.5)
Using extrapolateLinear(scale, new Vector3f(1,2,3), new Vector3f(2,4,6)))
0f (1.0, 2.0, 3.0)
0.5f (1.5, 3.0, 4.5)
1.0f (2.0, 4.0, 6.0)
1.5f (2.5, 5.0, 7.5)
2 – kk, well I’ve already used lines, so i ain’t changing it now