medihack
medihack

Reputation: 16627

Why does ArrowHelper not hit the target?

Why does the tip of the below ArrowHelper not directly hit the target sphere? It just misses it a bit. Is the below direction calculation not precise enough?

var geometry = new THREE.SphereGeometry(1, 16, 16);
var material =  new THREE.MeshNormalMaterial();
var mesh = new THREE.Mesh(geometry, material);
mesh.type = "node";
mesh.position.set(30, -87, -11);
scene.add(mesh);

geometry = new THREE.SphereGeometry(1, 16, 16);
material =  new THREE.MeshNormalMaterial();
mesh = new THREE.Mesh(geometry, material);
mesh.type = "node";
mesh.position.set(28, 44, -14);
scene.add(mesh);

var sourcePos = new THREE.Vector3(30, -87, -11);
var targetPos = new THREE.Vector3(28, 44, -14);
var direction = new THREE.Vector3().subVectors(targetPos, sourcePos);
var arrow = new THREE.ArrowHelper(direction.clone().normalize(), sourcePos, direction.length(), 0xff0000);
scene.add(arrow);

This is a direct follow up question to this question (I left it open as there are maybe better algorithms without ArrowHelper, but it seems the inaccuracy there is caused by the ArrowHelper problem described here).

Upvotes: 1

Views: 437

Answers (1)

WestLangley
WestLangley

Reputation: 104843

This is a precision problem in three.js r.58 when handling cases in which the arrow points approximately "straight up" -- or "straight down".

I think you will find that it works fine in other cases.

three.js r.58

Upvotes: 1

Related Questions