I’ve got a maths question, I am trying to work out how to tween a point away from a sphere centre. I know the sphere x,y,z position, the point’s x1,y1,z1 position and the distance the point should travel, is it possible to work out its new x2,y2,z2 coordinates from those values?
Something like that:
var point = new THREE.Vector3(10, 11, 12); var distance = 8; var direction = point.clone().normalize(); var pointNew = point.clone().addScaledVector(direction, distance); // your new point
I would say this is only true if the center of the sphere is the origin. The correct calculation of the direction vector is:
direction.subVectors( pointOnSphere, sphere.center ).normalize();
Thank you, much appreciated, both options work for me, and good to know how to handle cases when the origin is not centre. I thought I’d need some complicated maths to do that, seems like three.js is taking care of that : )
@iblaze it’s simple because you are just moving the point along a line, with direction taken from the centre of the sphere to the point on the sphere.
The actual sphere doesn’t need to appear anywhere in the maths, if you break down what three.js is doing it’s still very simple.