Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

15
LINES

< > BotCompany Repo | #1034863 // getProjectionDistance2 - used for multi-point gradient

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (5360L/30K).

// 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;
}

Author comment

Began life as a copy of #1034858

download  show line numbers  debug dex  old transpilations   

Travelled to 3 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1034863
Snippet name: getProjectionDistance2 - used for multi-point gradient
Eternal ID of this version: #1034863/3
Text MD5: c53d4293f210ebd98257feb59d43ee17
Transpilation MD5: 9b4f8051f2cc7748ef99be65efadbace
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-03-12 20:26:28
Source code size: 624 bytes / 15 lines
Pitched / IR pitched: No / No
Views / Downloads: 60 / 90
Version history: 2 change(s)
Referenced in: [show references]