Libraryless. Click here for Pure Java version (4686L/26K).
// from https://stackoverflow.com/questions/4103405/what-is-the-algorithm-for-finding-the-center-of-a-circle-from-three-points // (by Adam Gawne-Cain) static DoublePt circleCenterFrom3Points(DoublePt p1, DoublePt p2, DoublePt p3) { double ax = (p1.x + p2.x) / 2; double ay = (p1.y + p2.y) / 2; double ux = (p1.y - p2.y); double uy = (p2.x - p1.x); double bx = (p2.x + p3.x) / 2; double by = (p2.y + p3.y) / 2; double vx = (p2.y - p3.y); double vy = (p3.x - p2.x); double dx = ax - bx; double dy = ay - by; double vu = vx * uy - vy * ux; if (vu == 0) null; // Points are collinear, so no unique solution double g = (dx * uy - dy * ux) / vu; ret DoublePt(bx + g * vx, by + g * vy); }
download show line numbers debug dex old transpilations
Travelled to 3 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1033970 |
Snippet name: | circleCenterFrom3Points |
Eternal ID of this version: | #1033970/3 |
Text MD5: | 21029ee9a06cf7a7a2c048e3e95aaa1d |
Transpilation MD5: | a36ab6709ea420d2b4ac2732a68dc335 |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-01-15 03:27:49 |
Source code size: | 735 bytes / 20 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 171 / 222 |
Version history: | 2 change(s) |
Referenced in: | [show references] |