簡體   English   中英

從一行點創建一個點平面

[英]Create a plane of points from a row of points

我正在嘗試從一組初始點創建MATLAB中點的“平面”。 到目前為止,我只能使用下面顯示的算法創建一行點:

    % Generate molecular orientation and position
a = 4.309; % lattice constant in angstroms
l = 10; % number of lattices desired

placeHolder = [0 0 0 ; a/2 a/2 0; a/2 0 a/2; 0 a/2 a/2];    % centers of molecules

numMol = 4; %input('how many molecules are in the unit cell? \n # molecules = ');
numAtoms = 2; %input('how many atoms per molecule? \n # atoms per molecule = ');
atomPerUC = numMol*numAtoms; % number of atoms per unit cell
dir = zeros(numMol,3);      % array for orientations
atomPosition = zeros(numAtoms*l^3,3,numMol);        % array for positions of atoms
theta = zeros(numMol,1);        % array for theta values
phi = zeros(numMol,1);      % array for phi values
b = 1.54;      % bond length in angstroms

for kk = 1:numMol % generate unit cell
%     disp(['What is the molecular orientation for molecule ',num2str(kk),' ?']);
%     dir(kk,1) = input('u = '); % ask for user input for molecular orientations
%     dir(kk,2) = input('v = ');
%     dir(kk,3) = input('w = ');
    dir = [1,1,1;-1,1,1;-1,-1,1;1,-1,1];
    u = dir(kk,1);       % set variables for theta, phi computation
    v = dir(kk,2);
    w = dir(kk,3);

    theta(kk) = w/sqrt(u^2+v^2+w^2); % theta value for molecule k

    if v<0   % phi value for molecule k
        phi(kk) = 2*pi - acos(abs(v)/sqrt(u^2+v^2+w^2));
    else if v>0
           phi(kk) = acos(u/sqrt(u^2+v^2+w^2)); 
        end
    end

    theta = theta(kk); phi = phi(kk);     % set variables for theta, phi for x,y,z computation

    xp = placeHolder(kk,1);      % cooridnates of center of molecule k
    yp = placeHolder(kk,2);
    zp = placeHolder(kk,3);

    x1 = (b/2)*sin(theta)*cos(phi) + xp;        % cooridnates for atoms in molecule
    x2 = -(b/2)*sin(theta)*cos(phi) + xp;
    y1 = (b/2)*sin(theta)*sin(phi) + yp;
    y2 = -(b/2)*sin(theta)*sin(phi) + yp;
    z1 = (b/2)*cos(theta) + zp;
    z2 = -(b/2)*cos(theta) + zp;

    atomPosition(1,:,kk) = [x1 y1 z1];
    atomPosition(2,:,kk) = [x2 y2 z2];
end

for k = 1:numMol

    x01 = atomPosition(1,1,k); y01 = atomPosition(1,2,k); z01 = atomPosition(1,3,k);
    x02 = atomPosition(2,1,k); y02 = atomPosition(2,2,k); z02 = atomPosition(2,3,k);

    for ii = 1:l-1
        atomPosition(2*ii+1,:,k) = [(atomPosition(2*ii-1,1,k) + a) y01 z01];
        atomPosition(2*ii+2,:,k) = [(atomPosition(2*ii,1,k) + a) y02 z02];
    end

end

我的問題是,我不知道如何從此處將這些點的“行”轉換為點的“平面”。 可以將其視為獲取x軸上已知的點,並創建沿y方向向上移動的相似行以創建點的xy平面。

任何幫助/建議,將不勝感激!

雖然我不太了解您要做什么。 在簡單的情況下,您可以通過添加額外的尺寸從一排點移動到一個平面。

即。

x=[1,2,3,4,5]
y=x^2

更改為

x=[1,2,3,4,5]
y=[1,2,3,4,5]
[x,y] = meshgrid(x,y)
z=x^2+y^2

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM