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.)

답변 (1개)

Matt J
Matt J 2022년 12월 4일
이동: Matt J 2022년 12월 4일

0 개 추천

(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

Patrick Daly
Patrick Daly 2022년 12월 4일
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.
Matt J
Matt J 2022년 12월 4일
편집: Matt J 2022년 12월 4일
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))
Patrick Daly
Patrick Daly 2022년 12월 4일
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() )
Matt J
Matt J 2022년 12월 4일
Yes, did you try it?
Patrick Daly
Patrick Daly 2022년 12월 4일
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 2022년 12월 4일
편집: Matt J 2022년 12월 4일
How are you doing the orthogonal projection, if not by projecting into a 2D coordinate system in the plane?
Patrick Daly
Patrick Daly 2022년 12월 4일
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 2022년 12월 5일
편집: Matt J 2022년 12월 5일
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().
Patrick Daly
Patrick Daly 2022년 12월 10일
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 2022년 12월 11일
편집: Matt J 2022년 12월 11일
You're welcome, but please Accept-click the answer to indicate that your question has been resolved.

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

카테고리

제품

태그

질문:

2022년 12월 4일

편집:

2022년 12월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by