patching the area between multiple points

ive been using the patch() function for filling in the area between points. however patch needs the right order of points in order to work as expected.
im working with a function that delivers a points on a plane and i want to fill in the space between the points. depending on the angle of the plane the points are in different positions relative to eath other. so one fixed order for my path() functions doesnt work for all angles.
i need a function that takes points and fills the space in between regardless of the order they are given in.
(for extra context: the points correspond to the orthogonal projection of the vertices of a floating cuboid, changing the angle of the plane changes the "shadow" of the cuboid on the plane. i want that shadow to be filled in.)

Answers (1)

Matt J
Matt J on 4 Dec 2022
Moved: Matt J on 4 Dec 2022
(for extra context: the points correspond to the orthogonal projection of the vertices of a floating cuboid, changing the angle of the plane changes the "shadow" of the cuboid on the plane. i want that shadow to be filled in.)
The orthogonal projection of a cuboid is convex, but some of the projected vertices of the cuboid will not in general be on the convex boundary of the projected region, so we need to exclude those. This is easily done with convhull
k=convhull(x,y);
patch(x(k),y(k))

10 Comments

thanks! how would that apply to my 3-D points, if i put x,y,z into convhull i get an error saying they might be coplanear, which of course they are.
You should re-express the points in a 2D coordinate system (xp,yp) attached to the plane. Then,
k=convhull(xp,yp);
patch(x(k),y(k),z(k))
does that work if i want it to be coloured on the 2D plain in a 3D figure. the image shows my desired outcome (here i manually set the right order for patch() )
Yes, did you try it?
You should re-express the points in a 2D coordinate system (xp,yp) attached to the plane
im not sure how i would re-express the points..
thanks btw
Matt J
Matt J on 4 Dec 2022
Edited: Matt J on 4 Dec 2022
How are you doing the orthogonal projection, if not by projecting into a 2D coordinate system in the plane?
i make a plane from two vector - i have a function that perfoms gram schmidt for those vectors to get the orthonormal base - let M be the matrix of the orthonormal vectors, then P = M*transpose(conj(M)) is the projector - so P*x (x being a vertex on the cuboid) is the projected vector onto the plane (or for me: the projected vertex).
Matt J
Matt J on 5 Dec 2022
Edited: Matt J on 5 Dec 2022
Then you can get 2D coordinates by doing M'*x.
Incidentally, you shouldn't be using Gram-Schmidt as it is not a stable algorithm in general. Use orth(), qr(), or svd().
ive got it now!
im doing a project for college and the task was to write my own gram schmidt function, thats why im using it.
Thanks for your help!
Matt J
Matt J on 11 Dec 2022
Edited: Matt J on 11 Dec 2022
You're welcome, but please Accept-click the answer to indicate that your question has been resolved.

Sign in to comment.

Products

Tags

Asked:

on 4 Dec 2022

Edited:

on 11 Dec 2022

Community Treasure Hunt

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

Start Hunting!