How to draw circle in a 3D space?

44 visualizzazioni (ultimi 30 giorni)
Salad Box
Salad Box il 23 Set 2019
Commentato: Fabio Freschi il 25 Set 2019
Hi,
plane.png
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:
  1. Using line P1P5 as the diameter
  2. Using the mid point of line P1P5 as the center
  3. 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?

Risposta accettata

Fabio Freschi
Fabio Freschi il 23 Set 2019
Modificato: Fabio Freschi il 23 Set 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
  10 Commenti
Salad Box
Salad Box il 25 Set 2019
One more question:
Why Pc1 = P*R1' + C0?
Fabio Freschi
Fabio Freschi il 25 Set 2019
P are the points along the green circle R1 is the rotation matrix, C0 the center of the roto-translated circle. So: the green circumpherence is rotated (P*R1') and then translated to the new center (P*R1'+C0)

Accedi per commentare.

Più risposte (1)

darova
darova il 23 Set 2019
Another version
Rotation matrix from HERE

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by