// from https://codepen.io/tculda/pen/pogwpOw // (https://stackoverflow.com/questions/22356012/multiple-points-colors-gradient-on-html5-canvas) static double getProjectionDistance2(DoublePt a, DoublePt b, DoublePt c) { ret getProjectionDistance2(a.x, a.y, b.x, b.y, c.x, c.y); } static double getProjectionDistance2(double ax, double ay, double bx, double by, double cx, double cy) { var k2 = bx*bx - bx*ax + by*by -by*ay; var k1 = ax*ax - bx*ax + ay*ay -by*ay; var ab2 = (ax - bx)*(ax - bx) + (ay - by) * (ay - by); var kcom = (cx*(ax - bx) + cy*(ay-by)); var d2 = (k2 + kcom) / ab2; ret d2; }