# Creating a rectangular patch using random numbers

1 Ansicht (letzte 30 Tage)
Tishan Anantharajah am 27 Apr. 2023
Kommentiert: Les Beckham am 2 Mai 2023
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.
##### 0 Kommentare-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Akzeptierte Antwort

Les Beckham am 27 Apr. 2023
Bearbeitet: Les Beckham am 27 Apr. 2023
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 Kommentare1 älteren Kommentar anzeigen1 älteren Kommentar ausblenden
Les Beckham am 2 Mai 2023
You are quite welcome.

Melden Sie sich an, um zu kommentieren.

### Weitere Antworten (1)

chicken vector am 27 Apr. 2023
Bearbeitet: chicken vector am 27 Apr. 2023
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
##### 0 Kommentare-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Polygons finden Sie in Help Center und File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by