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

12
LINES

< > BotCompany Repo | #1034858 // getProjectionDistance - what exactly does it do?

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

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

// from https://codepen.io/tculda/pen/pogwpOw
// (https://stackoverflow.com/questions/22356012/multiple-points-colors-gradient-on-html5-canvas)

static double[] getProjectionDistance(DoublePt a, DoublePt b, DoublePt c){
  var k2 = b.x*b.x - b.x*a.x + b.y*b.y -b.y*a.y;
  var k1 = a.x*a.x - b.x*a.x + a.y*a.y -b.y*a.y;
  var ab2 = (a.x - b.x)*(a.x - b.x) + (a.y - b.y) * (a.y - b.y);
  var kcom = (c.x*(a.x - b.x) + c.y*(a.y-b.y));
  var d1 = (k1 - kcom) / ab2;
  var d2 = (k2 + kcom) / ab2;
  ret new double[] {d1, d2};
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1034858
Snippet name: getProjectionDistance - what exactly does it do?
Eternal ID of this version: #1034858/2
Text MD5: e37d6e827a161eb3375b63a0def4ab52
Transpilation MD5: 0460dd9385424f0727988004d5b464ba
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:00:11
Source code size: 532 bytes / 12 lines
Pitched / IR pitched: No / No
Views / Downloads: 52 / 86
Version history: 1 change(s)
Referenced in: [show references]