I have two Vector3 points A and B.
I want to get vector C placed of trajectory path from A to B, but add to it 100 pint to his length.
How can i calculate this vector?
You can increment a non-zero-lenth vector in three.js by length len
like so:
var oldLength = vector.length();
if ( oldLength !== 0 ) {
vector.multiplyScalar( 1 + ( len / oldLength ) );
}
So, here is how you compute the point C
.
var A = new THREE.Vector3( 10, 20, 30 );
var B = new THREE.Vector3( 20, 30, 40 );
var C = new THREE.Vector3();
var len = 10;
C.subVectors( B, A ).multiplyScalar( 1 + ( len / C.length() ) ).add( A );
three.js r.69
In a two dimentional context, this will give you the coordinates of C:
var oldLength = A.distanceTo(B);
var newLength = oldLength + 100;
if(oldLength > 0)
{
C.x = A.x + (B.x - A.x) * newLength / oldLength;
C.y = A.y + (B.y - A.y) * newLength / oldLength;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With