- You did not index into A properly. I think you do not understand matrices, and how to index into them.
- You did not use null properly, partly because you failed to correctly index into A, but also because you do not understand null, and what it does.
creation of a circular plane passing through three nodes and for central node
3 次查看(过去 30 天)
显示 更早的评论
Hi. I would like to generate a circular plane from three nodes + center nodes.
I'm using this code but I don't understand why a plane is generated that doesn't go through those three nodes (it only goes through the center node).
A = [28.9646 -21.3886 97.3614
23.1935 -19.9821 97.2254
27.9585 -16.222 95.2403];
A_mean = mean(A);
R = 5;
t = (0:359)';
a_A = A(1);
b_A = A(2);
c_A = A(3);
plane = R*[cosd(t),sind(t)]*null([a_A,b_A,c_A])' + A_mean(:)';
figure
plot3(A(:,1),A(:,2),A(:,3),'r.','Markersize',27);
hold on
plot3(A_mean(:,1),A_mean(:,2),A_mean(:,3),'r.','Markersize',27);
patch(plane(:,1),plane(:,2),plane(:,3),'k.');
hold off
axis equal
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1506499/image.png)
0 个评论
采纳的回答
John D'Errico
2023-10-9
编辑:John D'Errico
2023-10-9
It does not pass through those other points, because ... your code is wrong. Seems simple enough. What did you do incorrectly?
The rest of your code seems fine though. ;-)
A = [28.9646 -21.3886 97.3614
23.1935 -19.9821 97.2254
27.9585 -16.222 95.2403];
A_mean = mean(A);
R = 5;
t = (0:359)';
No problems so far. You want to create a circle of radius 5, and you generate a set of points in DEGREES to go around the circle. That is fine, as long as you use degree trig functions, which you do. Better to learn what radians are in the future, but nothing to complain about.
a_A = A(1);
b_A = A(2);
c_A = A(3);
WRONG. WRONG. WRONG.
That is not how you extract vectors as rows of A. Flat out wrong. Instead, you may have wanted to write this:
a_A = A(1,:);
b_A = A(2,:);
c_A = A(3,:);
But that is irrelevant, since what you really wanted to do was to subtract off one of those vectors from the other two, and apply orth to that result. That will give you a pair of vectors that form a basis for the planar subspace parallel to the plane the circle lies in. Then you add back the mean to that later on, translating that plane.
plane = R*[cosd(t),sind(t)]*orth((A(2:3,:) - A(1,:))')' + A_mean;
Now we can go back to your code.
figure
plot3(A(:,1),A(:,2),A(:,3),'r.','Markersize',27);
hold on
plot3(A_mean(:,1),A_mean(:,2),A_mean(:,3),'r.','Markersize',27);
patch(plane(:,1),plane(:,2),plane(:,3),'k.');
hold off
axis equal
Oh. By the way, you did not need to do this:
A_mean(:)'
A_mean is already a row vector. A_mean(:) turns it into a column vector. Then the transpose just makes it back into a row vector. So I took the : and the transpose out.
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!