Creating a rectangular patch using random numbers

조회 수: 2 (최근 30일)
Tishan Anantharajah
Tishan Anantharajah 2023년 4월 27일
댓글: Les Beckham 2023년 5월 2일
Hi I am currently producing four random points in a 3D space. With these points I would like to create a rectangular patch which i can then use to find the vectors between them, then the normal and finally the plane equation. However my problem with this is that I need the patch to be a quadrilateral with parallel lines. When using three points it is fine as all three points are within the same plane however when using four points. One of my points is always off. How can I fix this.
An example of what I mean is provided below.

채택된 답변

Les Beckham
Les Beckham 2023년 4월 27일
편집: Les Beckham 2023년 4월 27일
The chances of four random points in 3d being coplanar are virtually zero. The chances of them forming a parallelogram are infinitesimal. The first 3 points can be random, but if you want a parallelogram, you will have to calculate the fourth point from the first three points
p = rand(3,3); % create three random points in 3d
p(:,4) = p(:,3) + (p(:,1) - p(:,2)); % calculate the 4th point to form a parallelogram
p(:,5) = p(:,1); % duplicate the first point to form a closed shape
plot3(p(1,:), p(2,:), p(3,:), 'o-')
patch(p(1,:), p(2,:), p(3,:), 'g', 'FaceAlpha', 0.3)
text(p(1,1), p(2,1), p(3,1), 'p1') % label the points
text(p(1,2), p(2,2), p(3,2), 'p2')
text(p(1,3), p(2,3), p(3,3), 'p3')
text(p(1,4), p(2,4), p(3,4), 'p4')
grid on
  댓글 수: 2
Tishan Anantharajah
Tishan Anantharajah 2023년 4월 27일
Ok thank you this is what I was thinking as well but wanted confirmation.
Les Beckham
Les Beckham 2023년 5월 2일
You are quite welcome.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

chicken vector
chicken vector 2023년 4월 27일
편집: chicken vector 2023년 4월 27일
You can't really fix this.
A plane is univoquely defined by 3 points in space, so, most-probably, a fourth point won't lie on that plane and no bi-dimensional figure can match your requirements.
If you really want to pull-off some graphics you can plot every possible triangular patch as follows:
nPoints = 4;
dims = 3;
patchColor = [.8 .8 .8];
points = rand(dims,nPoints);
polyData = struct;
figure;
hold on;
for p = 1 : nPoints
scatter3(points(1,1),points(2,1),points(3,1),50,'k','filled');
polyData(p).patch = patch(points(1,1:3),points(2,1:3),points(3,1:3),patchColor,'FaceAlpha',0.3);
points = circshift(points,1,2);
end
hold off;
view([1,1,1])
polyData(1).patch
ans =
Patch with properties: FaceColor: [0.8000 0.8000 0.8000] FaceAlpha: 0.3000 EdgeColor: [0 0 0] LineStyle: '-' Faces: [1 2 3] Vertices: [3×3 double] Show all properties
This way you can access patch properties.
Notice that if you are looking ofr the vector connecting two points, you can just do the difference.
point1 = [3 4]';
point2 = [10 0]';
vector = point2 - point1
vector = 2×1
7 -4
versor = vector/norm(vector)
versor = 2×1
0.8682 -0.4961

카테고리

Help CenterFile Exchange에서 Polygons에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by