Clear Filters
Clear Filters

Creating a rectangular patch using random numbers

7 views (last 30 days)
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.

Accepted Answer

Les Beckham
Les Beckham on 27 Apr 2023
Edited: Les Beckham on 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

More Answers (1)

chicken vector
chicken vector on 27 Apr 2023
Edited: chicken vector on 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;
hold on;
for p = 1 : nPoints
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);
hold off;
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

Community Treasure Hunt

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

Start Hunting!