【问题标题】:Create a plane of points from a row of points从一行点创建一个点平面
【发布时间】:2015-12-07 17:35:19
【问题描述】:

我正在尝试从一组初始点创建一个“平面”,可以说是 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 方向向上移动的类似行,以创建点的 x-y 平面。

任何帮助/建议将不胜感激!

【问题讨论】:

  • 这是很多代码,仅用于尝试将向量重塑为数组。请发布minimal reproducible example,包括您要转换的“行”以及生成平面的尺寸。

标签: matlab matrix matrix-multiplication


【解决方案1】:

虽然我不完全了解您要做什么。在一个简单的情况下,您可以通过添加额外维度从一行点移动到一个平面。

即。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-10-10
    • 2019-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-21
    • 1970-01-01
    相关资源
    最近更新 更多