Problem in mathematics [solved]

start and end are two vectors. and this is a vector between them.
Preformatted text(start.add(end)).mult(0.5f);

but I need a new vector that be in 0.2 of distance between these two vectors . and changing 0.5 to 0.2 does not work.

I think that the only reason 0.5 works in your case (but 0.2 doesn’t) is because 0.5 is also conveniently the average, where as multiplying by 0.2 is going to return an unrelated vector that is slightly closer to (0, 0, 0) and not between the 2 at all.

You could also use the interpolate method to do that instead

Vector3f vectorBetween = start.clone();
vectorBetween.interpolateLocal(end, 0.5f); // 0.2f
Preformatted text(vectorBetween);
1 Like

its not about mult work wrong. its wrong about mult on added vectors.

you need to get difference vector (it is via substract, for example (1,1,1) → (3,3,3) then (2,2,2) is difference - but also care about negative numbers)
then you mult 0.2 from difference vector and add it to start vector again.

1 Like

You don’t care about negative numbers, either. Just that you add the partial vector back to the source (and not the destination). You just have to keep things consistent.

Vector3f relative = dest.subtract(source);
relative.multLocal(someFraction);
Vector3f v = source.add(relative);

That’s it. I believe all of this is covered in the “math for dummies” link at the top of the forum… because it’s super basic vector stuff.

1 Like

by care i could mean anything :slight_smile: like not using ABS. after this long time, you should know what people odd things can do :smiley:

but yes, thats it, 3 lines of code.

1 Like

Have a look at the Vector3f Linear Interpolation method In FastMath

1 Like