Libraryless. Click here for Pure Java version (5357L/30K).
1 | // from https://codepen.io/tculda/pen/pogwpOw |
2 | // (https://stackoverflow.com/questions/22356012/multiple-points-colors-gradient-on-html5-canvas) |
3 | |
4 | static double[] getProjectionDistance(DoublePt a, DoublePt b, DoublePt c){ |
5 | var k2 = b.x*b.x - b.x*a.x + b.y*b.y -b.y*a.y; |
6 | var k1 = a.x*a.x - b.x*a.x + a.y*a.y -b.y*a.y; |
7 | var ab2 = (a.x - b.x)*(a.x - b.x) + (a.y - b.y) * (a.y - b.y); |
8 | var kcom = (c.x*(a.x - b.x) + c.y*(a.y-b.y)); |
9 | var d1 = (k1 - kcom) / ab2; |
10 | var d2 = (k2 + kcom) / ab2; |
11 | ret new double[] {d1, d2}; |
12 | } |
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: | 115 / 167 |
Version history: | 1 change(s) |
Referenced in: | [show references] |