Planes and vectors in 3d
조회 수: 22 (최근 30일)
이전 댓글 표시
I have 3 points say (1,2,3) (5,6,7) (2,5,7). I have a palne z=1. I wanna plot the vectors forming from these points and see if these vectors cut the plane in any way, can anyone help me in this?
댓글 수: 0
채택된 답변
John D'Errico
2023년 2월 26일
편집: John D'Errico
2023년 2월 26일
Are these vectors with a tail at (0,0,0)? If so, then they must cross the plane, as long as the z-component is not zero. Or are you forming a vector as the line defined by any pair of those three points? In that case, one of the vectors would not cross the plane, since z would be constant.
That is, an infinite line is defined by two things: a point on the line, and a direction. Consider any of those vectors. If the point on the line, the tail, so to speak, is the origin.
syms t
P0 = [0,0,0];
V = [1,2,3];
Now ANY point along that line will be generated by the parameter t, for some value of t.
P(t) = P0 + V*t
For example:
P(0)
P(1)
P(-3.75)
Does the line cross a specific plane? This is trivial to decide. (Yes, if you appreciate what I said before, it is truly trivial, but we can still do it with mathematics.)
The plane z == 1 is also definably using mathematics. A plane is simply defined by a point in the plane, and a dot product with the normal vector to the plane. We might write the plane equation as
dot(X - Q0,Qnormal) == 0
there, the point in the plane is the point
Q0 = [0 0 1];
Qnormal = [0 0 1];
Now we can determine is the line intersects the plane, and even where it intersects the plane.
tsol = solve(dot(P(t) - Q0,Qnormal) == 0,t)
As long as a solution to that problem exits, then there is an intersection. The point of intersection is:
P(tsol)
As I said, pretty simple. Do you even need to use the symbolic toolbox? Well, no. But it sure makes things look nice.
We can even make the problem slightly more interesting. Suppose you define the line by the two points
P1 = [1,2,3];
P2 = [5,6,7];
The line will be defined the same way. By a point along the line. I'll pick P1, And a vector that points along that line.
P(t) = P1 + t*(P2 - P1)
Does that line intersect our plane of interest, and where? (Note that the plane need not be as simple as the one you have indicated, but the problem is no different.
tsol = solve(dot(P(t) - Q0,Qnormal) == 0,t)
P(tsol)
Does P(tsol) lie in the plane? We can verify that, if you don't trust me.
dot(P(tsol) - Q0,Qnormal)
As it must be. Again, simple to solve. Had the plane been some other less boring plane, it would still have been as trivial to solve. All you need do is define the plane equations, and the line equations.
Oh. Do you want to understand how to solve the problem without recourse to the symbolic toolbox solve? Again, trivial. Consider this last problem I solved. We know Q0, and Qnormal. Write out the plane equation, and expand it on paper.
dot(P1 + (P2 - P1)*t - Q0,Qnormal) = 0
Expanding that expression, we have
t*dot(P2 - P1,Qnormal) = -dot(P1 - Q0 , Qnormal)
And therefore we would have
t = -dot(P1 - Q0,Qnormal) / dot(P2 - P1,Qnormal)
We can try it now, using simple double precision operations.
tintersection = -dot(P1 - Q0 , Qnormal) / dot(P2 - P1,Qnormal)
So, the same as what solve returned previously.
댓글 수: 3
John D'Errico
2023년 2월 26일
And I showed you how to solve exactly that problem for two given points, did I not? You have three points. Then you have three pairs of points. Perform that same analysis three times. So where is the problem?
I showed you exactly how to solve the problem even without using solve, it takes literally one line of code, and syms were not required.
Did you not read my answer?
In fact, you can even get a little more sophisticated, and just test which of those points lie on different sides of the plane. All that requires is to know the sign of the result of a dot product. But there is no need to do so.
추가 답변 (1개)
Matt J
2023년 2월 25일
편집: Matt J
2023년 2월 26일
Clearly they all cut the plane since their z-components are all greater than 1.
More generally, if P is a point, plug t*P into the plane equation
t*dot(normal,P)=something
and solve for t, giving a value t0. If 0<=t0<=1, the position vector of P does intersect the plane. Otherwise it does not.
댓글 수: 2
Matt J
2023년 2월 26일
You're welcome, but please Accept-click the answer if it resolves your question.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!