# Silly Vector Math Question (SOLVED)

Anyone enjoy their maths? - I got a problem I hope people wont mind me posting here…

I got two vectors (A and B), and I need to find a vector location © given a static distance from (A) looking toward (B).

Is interpolation the ONLY way to compute this?

I got interpolation running but it just doesnt look right, maybe camera ‘focus/lens angle’ (without knowing the terminology) is making it look wrong.

Vector A is the Camera location

Vector B is the actual distant Star location

Distance is 400 units from Camera location (it can be in any direction)

Vector C is to be a billboard position to represent the Star that lies within the FarFrustrum of the Camera (400 is a start value for me).

However as i run the app and reverse away from the Star location, the billboard goes wandering off from the Star - it seems to be bored with the confines of maths and has made its own life! If instead I go toward the actual Star location the Billboard does eventually get closer to the star and they follow one another.

Is there another way to find a vector location between two Vectors? An easier way…?

If interpolation is the only possible way then the code im using is this…(for each axis)

billboardLocation.x = cam.getLocation().x + -400 * (difference.x) / difference.x

And yep, im doing the correct check to make sure this doesnt end up being an extrapolation if the Cam gets too close. Also im already doing checks if the distance value is a negative or positive numer as well.

Kind regards,

Chris

Examplecode helps a lot:)

Maybe you typed it wrong in here, but this:

billboardLocation.x = cam.getLocation().x + -400 * (difference.x) / difference.x

Is the equivalent of:

billboardLocation.x = cam.getLocation().x + -400

When I really think you wanted:

billboardLocation.x = cam.getLocation().x + -400 * (difference.x) / difference.length()

…probably. Also, -400 seems wrong but without the rest of the code it is hard to tell. I guess it depends on which way you calculated difference.

Or you could use the built-in vector methods:

[java]

Vector3f dir = farLocation.subtract( cam.getLocation() );

float length = dir.length();

dir.divideLocal(length); //dir is now normalized

float projection = Math.min( length, 400 );

billboardLocation.set( cam.getLocation() );

[/java]

…or something like that.

1 Like

idk if this helps you, but theres also [java] // amount is the fraction of the distance from start to end, 0 -> 1 and it returns a new Vector3f

FastMath.interpolateLinear(float amount, Vector3f start, Vector3f end, Vector3f);[/java]

pspeed said:

Or you could use the built-in vector methods:
[java]
Vector3f dir = farLocation.subtract( cam.getLocation() );
float length = dir.length();
dir.divideLocal(length); //dir is now normalized
float projection = Math.min( length, 400 );
billboardLocation.set( cam.getLocation() );
[/java]

...or something like that.

You're certainly correct, that interpolation code i entered is not correct.. im not sure where it went off track I did an app last night after posting the question to actually see what the output of it is, and well... it wasnt good :( Sorry, i should have checked this first. Since Im really bad with maths Ive taken what I understood to be working code and used it, though i take the blame for it not working - I was actually quite sure it was functional having done some calculator checks, but obviously not good enough.

However the code you provided is absolutely perfect, and works a treat! Thank you so much!

Wezrule: Thanks for the reply, i was looking at that function, and did muck around with it initially but i couldnt use a percentage for my app, it has to be based on distance unfortunately.

Kind regards,

Chris