Threejs - Collinear points

by black strings

HTML

<script src="https://rawgit.com/mrdoob/three.js/dev/build/three.js"></script>
<script src="https://rawgit.com/mrdoob/three.js/dev/examples/js/controls/OrbitControls.js"></script>

CSS

/* fix mouse click offset errors when doing drags */
body {
  margin: 0;
}

JavaScript

var scene, renderer, camera;
var cube;
var controls;

init();
lightSetup();
animate();

function init() {
  renderer = new THREE.WebGLRenderer({
    antialias: true
  });
  var width = window.innerWidth;
  var height = window.innerHeight;
  renderer.setSize(width, height);
  document.body.appendChild(renderer.domElement);

  scene = new THREE.Scene();

  var gridXZ = new THREE.GridHelper(1000, 100);
  scene.add(gridXZ);

  var axes = new THREE.AxesHelper(1000);
  scene.add(axes);

  camera = new THREE.PerspectiveCamera(45, width / height, 1, 10000);
  camera.position.y = 160;
  camera.position.z = 400;
  camera.lookAt(new THREE.Vector3(0, 0, 0));

  controls = new THREE.OrbitControls(camera, renderer.domElement);
  
  
  const sphereMaterial = new THREE.MeshBasicMaterial({color: 0xfff00});
  const sphereGeo1 = new THREE.SphereGeometry(2, 8, 8);
 	const sphere1 = new THREE.Mesh(sphereGeo1, sphereMaterial);
  const sphere2 = sphere1.clone();
  const sphere3 = sphere1.clone();
  const sphere4 = sphere1.clone();
  const spheres = [sphere1, sphere2, sphere3, sphere4];
  
  
  scene.add(sphere1);
  
  scene.add(sphere2);
  
  scene.add(sphere3);
  
   sphere4.position.copy(new THREE.Vector3(200, 220, 0));
  //scene.add(sphere4);
  
  var points = [
  	new THREE.Vector3(1, 1.05),
    new THREE.Vector3(2, 2),
    new THREE.Vector3(6,6),
    new THREE.Vector3(9,9)
  ];
  
  spheres.forEach( (sp, index) => {
  	sp.position.copy(points[index]);
  });
  
  console.log(isCollinear(points, .1));
  

  lightSetup();
 
}


function isCollinear(points, epsilon) {
	// equation of line
  // y = mx + b
  // b = y-intercept
  // m = slope
	// m = (y2 - y1) / (x2 - x1)
  var result = true;
  
  // Find slope
  var m = (points[1].y - points[0].y) / (points[1].x - points[0].x);
  
  // Find y-intercept
  var b = points[1].y - (m * points[1].x);
  
  // see if all point inputs x equals point outputs y with line equation
  // if it is then all points are on the same line 
  for(var i = 0;...