給定3個不共線的點的坐标,指明行數和列數,就可以計算出這個平行四邊形内所有元素的坐标。主要利用平行四邊形法則和定比分點公式,輸出可以是3維數組或者2維數組。
function location = position(ini,m,n)
% ------------------------------------
% This program is used to calculate the position of
% every matrix element in a 3D or 2D plane
%
% A m B
% * * * *
% n * * * *
% * * * *
% * * * *
% C D
%
% Input:
% ini: the initial 3 points of the plane, A B C, row vectors.
% ini must be a 3*3 or 3*2 matrix, for example:[0,0,0; 0,4,4; 4,0,0];
% m: the column of the matrix, say, m=5;
% n: the row of the matrix, say, n=5;
%
% Output:
% pos: 3D vectors. Each slice contains the positions of the row points.
% location: 2D vectors, stored by row.
% ------------------------------------
%% Validation
%Validate the form of ini
form = size(in