Libraryless. Click here for Pure Java version (5360L/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 getProjectionDistance2(DoublePt a, DoublePt b, DoublePt c) { |
5 | ret getProjectionDistance2(a.x, a.y, b.x, b.y, c.x, c.y); |
6 | } |
7 | |
8 | static double getProjectionDistance2(double ax, double ay, double bx, double by, double cx, double cy) { |
9 | var k2 = bx*bx - bx*ax + by*by -by*ay; |
10 | var k1 = ax*ax - bx*ax + ay*ay -by*ay; |
11 | var ab2 = (ax - bx)*(ax - bx) + (ay - by) * (ay - by); |
12 | var kcom = (cx*(ax - bx) + cy*(ay-by)); |
13 | var d2 = (k2 + kcom) / ab2; |
14 | ret d2; |
15 | } |
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: | 119 / 169 |
Version history: | 2 change(s) |
Referenced in: | [show references] |