1 | static double distancePointToLineSegment(Pt a, Pt b, Pt p) { |
2 | int x1 = a.x, y1 = a.y, x2 = b.x, y2 = b.y, x3 = p.x, y3 = p.y; |
3 | |
4 | float px=x2-x1; |
5 | float py=y2-y1; |
6 | float temp=(px*px)+(py*py); |
7 | float u=((x3 - x1) * px + (y3 - y1) * py) / (temp); |
8 | if (u>1) u=1; else if(u<0) u=0; |
9 | float x = x1 + u * px; |
10 | float y = y1 + u * py; |
11 | float dx = x - x3; |
12 | float dy = y - y3; |
13 | ret sqrt(dx*dx + dy*dy); |
14 | } |
download show line numbers debug dex old transpilations
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1009873 |
Snippet name: | distancePointToLineSegment |
Eternal ID of this version: | #1009873/1 |
Text MD5: | e65a340316c04b8f57846aa55fc47219 |
Author: | stefan |
Category: | javax / math |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2017-08-22 20:39:47 |
Source code size: | 417 bytes / 14 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 532 / 518 |
Referenced in: | [show references] |