how can i draw circle in 3D space with 3 point ?
36 views (last 30 days)
I need to draw a circle in space with 3 points that I have.
For example in the picture below I need to through the circle among the purple orange and the yellow dots.
and the arrays are :
% for yellow dots :
% for purple dots :
% for orange dots :
Roger Stafford on 18 Feb 2018
Let your three points be P1=[x1;y1;z1], P2=[x2;y2;z2], P3=[x3;y3;z3], and call the as yet unknown center P0 = [x0;y0;z0]. I will give you a partial solution which leaves some work for you to do.
v1 = cross(P2-P1,P3-P1);
v1 = v1/norm(v1); %Unit vector orthogonal to plane of 3 points
The center, P0, must satisfy these three equations:
dot(P0-P1,v1) = 0
dot(P0-(p2+P1)/2,P2-P1) = 0
dot(P0-(p3+P1)/2,P3-P1) = 0
Your task is to express these equations in a standard linear form A*P0=B where A is 3-by-3 and B is 3-by-1, so that matlab can solve for P0 as P0 = A\B. That gives you the center.
Next do this
v2 = P1-P0;
R = norm(v2);
v2 = v2/R;
v3 = cross(v2,v1);
v3 = v3/norm(v3);
Now you have mutually orthogonal unit vectors v2 and v3 both parallel to the plane of the desired circle. Finally do this:
t = linspace(0,2*pi);
P = repmat(P0,1,numel(t)) + R*(v2*cos(t) + v3*sin(t));
plot3(P(1,:),P(2,:),P(3,:),'y-') % This should give you your circle
If you want only an arc of a circle, change the linspace limits appropriately.