javascript - How to calculate the centre point of a circle given three points? -


i using javascript , know positions of 3 points. wish use these find out center point of circle.

i have found logic (not chosen answer 1 11 upvotes) : https://math.stackexchange.com/questions/213658/get-the-equation-of-a-circle-when-given-3-points

but can't seem head around how write logic it.

i can't use bounding box way, has done using 3 points :)

any ideas ?

my favorite resolution:

translate 3 points bring 1 of them @ origin (subtract (x0,y0)).

the equation of circle through 2 points , origin can written

2x.xc + 2y.yc = x² + y² 

plugging coordinates of 2 points, easy system of 2 equations in 2 unknowns, , cramer

xc = (z1.y2 - z2.y1) / d yc = (x1.z2 - x2.z1) / d  d = 2(x1.y2 - x2.y1), z1 = x1²+y1², z2 = x2²+y2² 

to translated (add (x0,y0)).


the formula fails when 3 points aligned, diagnosed d = 0 (or small in comparison numerators).


        x1-= x0; y1-= y0; x2-= x0; y2-= y0;          double z1= x1 * x1 + y1 * y1;         double z2= x2 * x2 + y2 * y2;         double d= 2 * (x1 * y2 - x2 * y1);          double xc= (z1 * y2 - z2 * y1) / d + x0;         double yc= (x1 * z2 - x2 * z1) / d + y0; 

Comments

Popular posts from this blog

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

html - Outlook 2010 Anchor (url/address/link) -

android - How to create dynamically Fragment pager adapter -