본문 바로가기
Matlab

Matlab으로 fcc 3d frame 만들기

by intermetallic 2023. 2. 25.

 

% Define the parameters
n = 100; % number of atoms
a = 0.5; % lattice parameter
L = ceil(n^(1/3))*a; % total size of the cubic frame

% Generate the FCC lattice points
[x,y,z] = meshgrid(0:a:L-a);
xyz = [x(:) y(:) z(:)];
xyz_odd = xyz(mod(sum(floor(bsxfun(@rdivide, xyz, a)), 2), 2) == 1,:);
xyz_even = xyz(mod(sum(floor(bsxfun(@rdivide, xyz, a)), 2), 2) == 0,:);
FCC_points = [xyz_odd; xyz_even];

% Choose n random atoms from the FCC lattice
rng(1); % set random seed for reproducibility
random_index = randperm(size(FCC_points,1), n);
atoms = FCC_points(random_index,:);

% Plot the atoms
scatter3(atoms(:,1), atoms(:,2), atoms(:,3), 50, 'filled');
axis equal;

'Matlab' 카테고리의 다른 글

Matlab으로 원 그리기  (0) 2023.02.24

댓글