Set boundaries to a plane equation

14 views (last 30 days)
S Justin
S Justin on 11 Feb 2018
Edited: S Justin on 12 Feb 2018
I have a surface with four edges, namely (x1, y1, z1), (x2, y2, z2), (x3, y3, z3), (x4, y4, z4). Those four points are always coplanar and they form a rectangle. I can find a plane equation with any of 3 coordinates above, however, that equation can be applied infinitely along x, y and z. How to limit the equation so that it is valid within the surface only? In other words, how to set boundaries to a plane equation in matlab coding
i tried searching but to no avail. Thank you.

Accepted Answer

John D'Errico
John D'Errico on 11 Feb 2018
In THREE dimensions, FOUR points do NOT define a plane. (Well, you might get lucky, and all 4 points lie in the same plane. Luck never seems to happen for me.)
As you state, you can pick any three of those points and define a plane from them. Think of it as if 4 points define a tetrahedron. In general, they do. There are 4 planes that define a tetrahedron, the 4 facets of the tetrahedron. As well, there are 4 ways to choose 3 points from the set of 4. That is not a coincidence.
So you might decide to bound a volume as the intersection of 4 half-spaces, thus the set of points that lie entirely on one side of a plane. That would create a tetrahedron if the resulting volume was closed and bounded.
But I also sincerely don't think that is what you are asking. You talk about 4 edges, defined by 4 points, so essentially a quadrilateral region.
I think you are looking for some way to define a surface by 4 points in three dimensions. Most of the time, that surface will not be a planar one, unless as I said before, you got lucky. Good luck on that ever happening. In fact though, there are infinitely many ways to define a general surface through 4 points in 3-dimensions. This is a general problem of interpolation, one that has plagued users of MATLAB (and mathematics) forever and will do so forever, because as I said, there is no unique, simple solution.
You will typically need to choose an interpolation method, then accept what and where it brings you. But maybe what you really want is that tetrahedron. In that case, it is just 4 planes, and you already know how to do that.
  5 Comments
John D'Errico
John D'Errico on 11 Feb 2018
Edited: John D'Errico on 11 Feb 2018
Many times how you will attack a problem depends on what you need to do in the end. This is as true in MATLAB as it is in mathematics in general, even though I have often said that MATLAB is not mathematics, but only an approximation thereof.
So if the 4 points are always coplanar, then you could pick any three of them, forming the planar region. But that still leaves you with the requirement that anything that happens must live in the quadrilateral region.
Personally, I tend to attack problems like this by reducing the 3-d problem to a 2-d one. That is, you have a planar quadrilateral region, embedded in a 3-d domain. So I would transform the problem be projecting it into the 2-d subspace of the plane. Work in there, then you can always project back out again. Sigh. That sounds like mathematical crap if I ever heard it. Easier is to show you how to do it. ;-)
So lets start with 4 points that happen to lie in a plane, in a quad, but also in 3-d.
So consider the rows of XYZ as points in R^3 I know they lie in the same plane because I constructed the 3rd point as a sum from points 2 and 4, and [0 0 0] is also in the plane. (Hopefully that makes sense.)
XYZ = [0 0 0 ; 1 1 0 ; 2 4 2 ; 0 1 1];
So the quadrilateral runs from points 1-2-3-4, then back to 1.
Ok, now we can mathematically define a plane by a point in the plane, and by the normal vector to the plane. Another way to define a plane is in terms of the projection matrix into the plane. I will use the latter form.
We can verify first that these points lie in a plane.
% A point in the plane. I'll just use the mean.
P0 = mean(XYZ);
% Are the points coplanar?
% If they are, then rank will return 2 here:
Note that this computation relies on a trick in MATLAB that was introduced in R2017. Older releases will need to use bsxfun.
rank(XYZ - P0)
ans =
2
% the normal vector
format long g
N = null(XYZ - P0)
N =
-0.577350269189626
0.577350269189626
-0.577350269189626
Project the points into their 2-d planar subspace. The projection matrix is given by orth.
proj = orth((XYZ - P0).')
proj =
-0.408248290463863 0.707106781186547
-0.816496580927726 -6.93889390390723e-17
-0.408248290463863 -0.707106781186547
Now the projection into a 2-d subspace is easy.
UV = (XYZ - P0)*proj
UV =
1.83711730708738 1.11022302462516e-16
0.612372435695794 0.707106781186547
-3.06186217847897 -2.22044604925031e-16
0.612372435695794 -0.707106781186547
plot(UV([1 2 3 4 1],1),UV([1 2 3 4 1],2),'r-o')
grid on
We can work with the points as if they lie in the (x,y) plane now. This has been reduced to a purely 2-d problem.
Of course, we can always go back. Pick some point in the (U,V) plane.
uv0 = [-0.5 0.25];
We can test to see if it is inside the quadrilateral, most easily using just inpolygon. But other methods will also apply.
inpolygon(uv0(1),uv0(2),UV(:,1),UV(:,2))
ans =
logical
1
hold on
plot(uv0(1),uv0(2),'b+')
It is easy to send this point in the (u,v) plane back into the original space,
uv0*proj' + P0
ans =
1.13090084052857 1.90824829046386 0.777347449935295
Anyway, that is how I would do things. I hope it makes sense. By working in the transformed, projected subspace, now you can think of things in 2-dimensions, not a complicated 3-d.
You still live with the question of how to restrict things to the quadrilateral. But that depends on what you will do with all of this.
Are you intending to use this in an optimization problem? Do you want to generate random points that lie inside the quadrilateral? I could guess a lot of things you MIGHT do. But as I said before, what you need to do in the end often impacts the mathematics you will use.
S Justin
S Justin on 12 Feb 2018
Edited: S Justin on 12 Feb 2018
Yes it is. You can imagine those four points as the edges of solar cell and I'll check if the light projection reaches the surface of the solar cell at that particular point. The points are not randomly generated. Thank you very much it is what i am searching for. I am gonna pick up those vector space knowledge again

Sign in to comment.

More Answers (2)

Matt J
Matt J on 11 Feb 2018
Edited: Matt J on 11 Feb 2018
Using VERT2LCON (Download), you can derive a system of inequalities and equalities giving the region bounded by the vertices,
[A,b,Aeq,beq]=vert2lcon( [ x1, y1, z1 ; x2, y2, z2 ; x3, y3, z3 ;x4, y4, z4 ])

Matt J
Matt J on 11 Feb 2018
Edited: Matt J on 11 Feb 2018
(1) Find the best fit plane using all 4 points
V=[ x1, y1, z1 ; x2, y2, z2 ; x3, y3, z3 ;x4, y4, z4 ];
mu=mean(V);
[~,~,N]=svd(V-mu,0);
n=N(:,end).'; d= dot(n,mu); %Equation of plane is dot(n,x)=dot(n,mu);
(2) Project all the points into 2D coordinate system of the plane,
xy=V*N(:,1:2);
(3) Use VERT2LCON (Download), to get inequalities for the region bounded by the 2D points,
[A,b]=vert2lcon( xy );
(4) Map the inequality data back to 3D,
A_3d=A*N(:,1:2).';
b_3d=b;

Community Treasure Hunt

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

Start Hunting!