There is a plane defined by 3 points in 3D space.
I need to get the 4 edges points of a rectangle that:
- Lies on the plane.
- Has Width and high of w and h.
- Centered at the Z axis.
- One of it side is parallel to the XY plane.
How can I get the 4 edges points using Matlab?
I will update this post with my progress, if I have any.
Edit: I have completely modified my Matlab code in order
1) to simplify it.
2) to fullfill the requirement of a given length and width.
I have removed the previous program because it has no longer interest.
clear all;close all;hold on;axis equal P1=rand(3,1);P2=rand(3,1);P3=rand(3,1);w=1.2;h=0.7; M=[P1,P2,P3]; c=det(M)/det([M(1:2,:);ones(1,3)]); %kind of Cramer formulas C=[0;0;c]; V1=P1-C;V3=P3-C; a=V1(3)/V3(3);V1=V1-a*V3; N=cross(V1,V3);V2=cross(N,V1); V1=V1/norm(V1);V2=V2/norm(V2); S=[C,C,C,C]+[(w/2)*V1,(h/2)*V2]*[1 -1 -1 1;1 1 -1 -1]; I=[1,2,3,4,1];plot3(S(1,I),S(2,I),S(3,I)); plot3(C(1),C(2),C(3),'or'); plot3(M(1,:),M(2,:),M(3,:),'*r') S1=S(:,1);S2=S(:,2);S3=S(:,3);Its principle is as follows.
Let $(P)$ denote the (affine) plane determined by points $P_k$.
Let $(P^*)$ be the vector plane associated with $(P)$ (i.e., parallel to $(P)$ passing through the origin).
Let $ \ C = (P) \ \cap \ Oz.$ We will go way and back from $(P)$ to $(P^*)$ by substracting or adding $C$.
1) Initial data : points $P_k$, $k=1\cdots3$ and side lengths $w$ and $h$.
2) Define $V_1=P_1-C=\vec{CP_1}$ and $V_3=P_3-C=\vec{CP_3} \ $ (provisional basis for $(P^*)$).
3) First modification of $V_1$ so that it is parallel to xy plane.
4) Computation of $V_2 \in (P^*)$, orthogonal to $V_1$ (using the two cross products trick)
5) Final orthonormalization of basis $(V_1,V_2)$.
6) The vertices of the rectangle are $S_k = C \pm (w/2)V_1\pm(h/2)V_2$.
Edit: Explanations for the Cramer formulas
Let $ux+vy+wz=h$ be the plane equation. The point of intersection $C(0,0,c)$ of $(P)$ with the z-axis has its last coordinate $c=h/w$. This ratio can be transformed into the ratio of two determinants. We start from the system:
$$\begin{cases} ux_1 & + & vy_1 & + & wz_1 & = & h \\ ux_2 & + & vy_2 & + & wz_2 & = & h \\ ux_3 & + & vy_3 & + & wz_3 & = & h \end{cases}$$
The Cramer formula for $w$ is $w=det(S)/det(M)$ with
$$det(M)=\begin{vmatrix} x_1 & y_1 & z_1 \\ x_2 & y_2 & z_2 \\ x_3 & y_3 & z_3 \end{vmatrix} \ \ and \ \ det(S)=\begin{vmatrix} x_1 & y_1 & h \\ x_2 & y_2 & h \\ x_3 & y_3 & h \end{vmatrix}=h \begin{vmatrix} x_1 & y_1 & 1 \\ x_2 & y_2 & 1 \\ x_3 & y_3 & 1 \end{vmatrix}.$$
Note: For a good recapitulation on determinants, see:
www.math.utah.edu/~gustafso/determinants.pdf