# 2 requests for features

These are some things, that I wished were implemented at the time when I needed them. I don’t personally require them anymore, because I implemented my own way around it. But i think it may help people in the future if they require it.

1 - There is a FastMath.Interpolate() method, which can find vertices between 2 points on a line using a float. 0 → 1. I think that a value of greater than 1 should extrapolate it. Or have a separate method called FastMath.extrapolate(), where anything greater than 1 will extrapolate, while < 1 will use the interpolate method internally.

2 - There is a Line shape but in order to actually create any real shape using it, you have to join a lot of Line shapes together, which can become annoying. I suggest a CompoundLine shape class, which for example has a method append(Vector3f vector), which joins the next point to the existing line.

And sorry if these features already exist, but I couldn’t find them.

1 - Nice idea, if you provide the code we can add that

2 - Combining primitives isnt really a good way to create meshes anyway, you should use custom meshes, maybe create your own Factory classes for them

1 - This works AFAIK :P, 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

[java]

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);

}[/java]

Edit: Sorry i should probably have shown a test of it, here:

[java]

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))); }[/java]

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 :P
2 Likes

Thanks for this it’s been added to the FastMath class.

awesome glad to help, although it wasn’t much