logPointsCrossLines

by Darby Rathbone

HTML

<canvas id='can'></canvas>

CSS

html,
body {
  scrollbar
  width: 100%;
  height: 100%;
  margin: 0px;
  border: 0;
  overflow: hidden;
  /*  Disable scrollbars */
  display: block;
  /* No floating content on sides */
    -ms-overflow-style: none; /* for Internet Explorer, Edge */
  scrollbar-width: none; /* for Firefox */
  overflow-y: scroll;
  overflow:hidden;
}
#can{
  overflow: hidden;
}

JavaScript

const htmlCanvas = document.getElementById("can"),
  context = htmlCanvas.getContext("2d"),
  m = {
    x: 0,
    y: 0,
  },
  Gpoints = [],
  last = {
    x: 0,
    y: 0,
  },
  mid = {},
  bisect = [],
  circle = 2 * Math.PI;
var  Gcircles=[];
initialize();

function initialize() {
  window.addEventListener("resize", resizeCanvas, false);
  window.addEventListener("mousedown", mouseDown, false);
  m.x = window.innerWidth;
  m.y = window.innerHeight;
  resizeCanvas();
}

function mouseDown(event) {
  
  if (
    !Gpoints.find(function (v) {
      return v[0] == event.offsetX && v[1] == event.offsetY;
    })
  )
    Gpoints.push([event.offsetX,event.offsetY]);
    //console.log(Gpoints);
  var temppoints = Gpoints.slice(),
  temp = delaunayTriangulateWithCircles(Gpoints);
Gcircles =[];
console.log(temppoints);
  temp.circles.forEach(function(a){
    Gcircles.push(a);
  });
  //console.log(Gcircles)
  resizeCanvas();

}
function delaunayTriangulateWithCircles(points) {
  // Clone input so we can append supertriangle points
  points = points.map(p => [...p]);

  // Supertriangle that encloses all points
  const minX = Math.min(...points.map(p => p[0]));
  const minY = Math.min(...points.map(p => p[1]));
  const maxX = Math.max(...points.map(p => p[0]));
  const maxY = Math.max(...points.map(p => p[1]));

  const dx = maxX - minX;
  const dy = maxY - minY;
  const deltaMax = Math.max(dx, dy);
  const midx = (minX + maxX) / 2;
  const midy = (minY + maxY) / 2;

  const superA = points.push([midx - 20 * deltaMax, midy - deltaMax]) - 1;
  const superB = points.push([midx, midy + 20 * deltaMax]) - 1;
  const superC = points.push([midx + 20 * deltaMax, midy - deltaMax]) - 1;

  let triangles = [
    [superA, superB, superC]
  ];

  // Store circumcircles: { triangle: [i,j,k], x, y, r }
  let circles = [];

  function circumcircle(ax, ay, bx, by, cx, cy) {
    const A = bx - ax, B = by - ay;
   ...