I created a small function that seems to have a glitch...
function determineIfPointIsBetweenTwoOtherPoints (pointA, pointB, pointToCheck) {
var vectorAB = new THREE.Vector3();
vectorAB.subVectors(pointA, pointB).normalize();
var vectorBA = new THREE.Vector3();
vectorBA.subVectors(pointB, pointA).normalize();
var vectorAPointToCheck = new THREE.Vector3();
vectorAPointToCheck.subVectors(pointA, pointToCheck).normalize();
var vectorBPointToCheck = new THREE.Vector3();
vectorBPointToCheck.subVectors(pointB, pointToCheck).normalize();
if(vectorAPointToCheck.dot(vectorAB) < 0 || vectorBPointToCheck.dot(vectorBA) < 0)
return false;
else
return true;
}
https://i.sstatic.net/8fWBG.png What's going wrong? My function output indicates that the left point is between the two on the right
@Pete The revised function is:
function checkIfPointLiesBetweenTwoOthers (pointA, pointB, pointToCheck) {
var vectorAB = new THREE.Vector3();
vectorAB.subVectors(pointA, pointB);
var lengthAB = vectorAB.length();
var vectorBA = new THREE.Vector3();
vectorBA.subVectors(pointB, pointA);
var lengthBA = vectorBA.length();
var vectorAPointToCheck = new THREE.Vector3();
vectorAPointToCheck.subVectors(pointA, pointToCheck);
var vectorBPointToCheck = new THREE.Vector3();
vectorBPointToCheck.subVectors(pointB, pointToCheck);
var vectorToPointA = new THREE.Vector3();
vectorToPointA.subVectors(pointToCheck, pointA);
var lengthToPointA = vectorToPointA.length();
if(lengthToPointA > lengthBA) {
return false;
} else if(vectorToPointA.dot(vectorBA) > 0.999999 * vectorToPointA.x * vectorBA.x + vectorToPointA.y * vectorBA.y + vectorToPointA.z * vectorBA.z) {
return true;
} else {
return false;
}
}
Now (the dark sphere in the image below represents point C), it returns true for this case only when I add the 0.999999 value. Otherwise, it works accurately for this scenario... https://i.sstatic.net/JtwVW.png However, in another situation without 0.9999, it indicates that point C is not between points A & B with these coordinates...
var t1 = new THREE.Vector3(1,1,1); //A
var t2 = new THREE.Vector3(-1,1,1); //B
var t3 = new THREE.Vector3(-0.3999999999999999,1,1); //C