MATLAB: How to traverse a circle while identifying given points

circlecircle pointscircular-traverseindentifying circle pointsMATLABtraverse

My input data are three points, lets say p1, p2 and p3. I can obtain the equation of a circle that goes through p1, p2 and p3. Now what I want to do is traverse the circle in my direction of choice, starting always at the "top" of the circle (max y), identifying each time one of the three initial points is found. As a result I want a three row array with its row number matching the order in which the three initial points p1, p2 and p3 where found. These means the first row must contain the first point found, the second row contains the second point found, and the third row contains the last point found.
Than you for your time!

Best Answer

Let P1 = (x1,y1), P2 = (x2,y2), P3 = (x3,y3) be the three points and their respective coordinates. Perform these computations:
A4 = 2*((x2-x1)*(y3-y1)-(x3-x1)*(y2-y1)); % Four times triangle's signed area
R2 = [x1^2+y1^2,x2^2+y2^2,x3^2+y3^2]/A4;
x0 = dot([y2-y3,y3-y1,y1-y2],R2); % Coordinates of circle's center
y0 = dot([x3-x2,x1-x3,x2-x1],R2);
a1 = mod(atan2(-(x1-x0),y1-y0),2*pi); % Angles counterclockwise
a2 = mod(atan2(-(x2-x0),y2-y0),2*pi); % from "top"
a3 = mod(atan2(-(x3-x0),y3-y0),2*pi);
[~,ix] = sort([a1,a2,a3]);
M = [x1,y1;x2,y2;x3,y3];
M = M(ix,:); % Points in order counterclockwise from top
Array M will be the coordinate pairs listed in counterclockwise order around from the "top" of the circle. If you want to go in clockwise order, just apply 'fliplr' to 'ix' or else do a descending 'sort'.