47 views (last 30 days)

Hi,

I would like to draw 2 circles. One in plane [P1 P6 P5], the other in plane [P1 P8 P5].

RGB values of points P1, P5, P6 and P8 are known. E.g., the RGB values of P1 is [R1 G1 B1]; the RGB values of P5 is [R5 G5 B5].

Requirements:

- Using line P1P5 as the diameter
- Using the mid point of line P1P5 as the center
- P6 and P8 are points only used for deciding the location of the planes, P6 and P8 does not necessarily need to be contained in the circles. They could be outside of the circles.

Any thoughts please?

Fabio Freschi
on 23 Sep 2019

Edited: Fabio Freschi
on 23 Sep 2019

The solution requires the definition of a rotation matrix. There are several ways to use it. Matlab has the rotx, roty and rotz functions, but they only work with one rotation at time. My implementation (see attachment) works by defining the new coordinate system identified by the position of the new center P0, any point along the new z axis Pz, and any point along the new x axis Px. So the call is R = rotationMatrix(P0,Pz,Px); I understand that these few words can be complex to understand but if you need details, I can explain further. Now the code

clear variables, close all

% points

P1 = [0 0 0]; P8 = [0 0 1]; P5 = [1 .5 2]; P6 = [2 2 3];

% plot

h = figure; hold on

plot3(P1(1),P1(2),P1(3),'o')

plot3(P8(1),P8(2),P8(3),'o')

plot3(P5(1),P5(2),P5(3),'o')

plot3(P6(1),P6(2),P6(3),'o')

axis equal, view([1 1 1])

% center

C0 = (P1+P5)/2; % center

figure(h), plot3(C0(1),C0(2),C0(3),'*')

% radius

R = sqrt(sum((P5-P1).^2,2))/2;

% circumpherence in local coordinates

nPt = 100;

alpha = linspace(0,2*pi,nPt).';

P = [R.*cos(alpha) R.*sin(alpha) zeros(nPt,1)];

% direction orthogonal to circumpherence 1

v1 = cross(P8-P1,P5-P1);

figure(h), quiver3(C0(1),C0(2),C0(3),v1(1),v1(2),v1(3))

% rotation matrix

R1 = rotationMatrix(C0,C0+v1,P5);

% circumpherence 1 rotate points

Pc1 = P*R1'+C0;

plot3(Pc1(:,1),Pc1(:,2),Pc1(:,3),'-');

% direction orthogonal to circumpherence 2

v2 = cross(P6-P1,P5-P1);

figure(h), quiver3(C0(1),C0(2),C0(3),v2(1),v2(2),v2(3))

% rotation matrix

R2 = rotationMatrix(C0,C0+v2,P5);

% circumpherence 2 rotate points

Pc2 = P*R2'+C0;

plot3(Pc2(:,1),Pc2(:,2),Pc2(:,3),'-');

Please check if I have provided everything you need, because I have many personal utility functions in matalb path

Fabio Freschi
on 25 Sep 2019

Sign in to comment.

Sign in to answer this question.

Opportunities for recent engineering grads.

Apply Today
## 0 Comments

Sign in to comment.