Skip to content

Commit aaef1b7

Browse files
committed
Upload code file.
1 parent 2635bb3 commit aaef1b7

28 files changed

+675
-0
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# 晶格系统可视化
2+
1. 代码文件中 `main_surface2.m``main_wigner.m` 为可执行脚本,其它皆为使用到的函数。两文件中,前者为生成三种晶系对应正格子和倒格子的代码,后者为生成三种晶系对应的WS原胞的代码。绘制某种晶格的正格子或者倒格子需要将对应部分代码取消注释。整体代码稍显繁杂,没有做重构工作,具体细节自行研究。
3+
4+
2. gif文件夹下为上述3D图动态旋转动画,可用im2gif函数生成。

coor_trans.m

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
function [ cc ] = coor_trans( c, trans_mat )
2+
%COOR_TRANS Get Cartesian coordinate from another coordinate by
3+
%transformation matrix.
4+
% Detailed explanation goes here
5+
6+
cc = c*trans_mat;
7+
end
8+

create_atom.m

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
function [ X, Y, Z, C ] = create_atom( coordinate, r)
2+
%CREATE_ATOM Create one atom and return surface matrix data.
3+
% Detailed explanation goes here
4+
5+
range = 100;
6+
% phi =linspace(0,2*pi,range);
7+
% thet = linspace(0,pi,range);
8+
% [phi,thet] = meshgrid(phi, thet);
9+
% X = r*sin(thet).*cos(phi);
10+
% Y = r*sin(thet).*sin(phi);
11+
% Z = r*cos(thet);
12+
% C = sin(X+Y+Z);
13+
[X,Y,Z] = sphere(range);
14+
C = sin((X+Y+Z)/3);
15+
X = r*X + coordinate(1);
16+
Y = r*Y + coordinate(2);
17+
Z = r*Z + coordinate(3);
18+
end
19+

create_bone.m

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
function [ X, Y, Z, C ] = create_bone( cstart, cend, radius, varargin )
2+
%CREATE_BONE Create one bone between two point on a special coordinate
3+
%described by transformation matrix and return surface matrix data on
4+
%Cartesian coordinates.
5+
% Detailed explanation goes here
6+
7+
if length(varargin) == 1
8+
trans_mat = varargin{1};
9+
else
10+
trans_mat = [1,0,0;0,1,0;0,0,1];
11+
disp('Warning: trans_mat param error ! defult to using cartesian coordinates !');
12+
end
13+
cstart_c = cstart*trans_mat;
14+
cend_c = cend*trans_mat;
15+
vector_c = cend_c - cstart_c;
16+
l = norm(vector_c);
17+
t = acos(vector_c(3)/l);
18+
if norm(vector_c(1:2)) ~= 0
19+
if vector_c(2) >= 0
20+
p = acos(vector_c(1)/norm(vector_c(1:2)));
21+
else
22+
p = -acos(vector_c(1)/norm(vector_c(1:2)));
23+
end
24+
else
25+
p = 0;
26+
end
27+
[X, Y, Z, C] = create_bones(cstart_c, t, p, l, radius);
28+
end
29+

create_bones.m

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
function [ X, Y, Z, C ] = create_bones( coordinate, t, p, l, r)
2+
%CREATE_BONES Create one bone whitch starts from a point and described by
3+
%Ball coordinates with radius of r.
4+
% Detailed explanation goes here
5+
6+
range = 20;
7+
phi = linspace(0,2*pi, range);
8+
h = linspace(0,l,range);
9+
[phi, h] = meshgrid(phi, h);
10+
X = r*cos(phi);
11+
Y = r*sin(phi);
12+
Z = h;
13+
14+
X_ = cos(t)*X+sin(t)*Z;
15+
Z = -sin(t)*X+cos(t)*Z;
16+
17+
X = cos(p)*X_-sin(p)*Y;
18+
Y = sin(p)*X_+cos(p)*Y;
19+
20+
X = X+coordinate(1);
21+
Y = Y+coordinate(2);
22+
Z = Z+coordinate(3);
23+
C = phi;
24+
end
25+

create_crystal_system.m

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
function [ crystal_system ] = create_crystal_system( trans_mat, limits )
2+
%CREATE_CRYSTAL_SYSTEM Summary of this function goes here
3+
% Detailed explanation goes here
4+
5+
[x,y,z] = meshgrid(limits(1,1):limits(1,2), limits(2,1):limits(2,2), ...
6+
limits(3,1):limits(3,2));
7+
x = reshape(x, [numel(x),1]);
8+
y = reshape(y, [numel(y),1]);
9+
z = reshape(z, [numel(z),1]);
10+
crystal_system = [x,y,z]*trans_mat;
11+
end
12+

create_parallelogram.m

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
function [ X,Y,Z,C ] = create_parallelogram( points, trans_mat )
2+
%CREATE_PARALLELOGRAM Summary of this function goes here
3+
% Detailed explanation goes here
4+
[X,Y,Z,C] = create_surface([points(1,:);points(2,:);...
5+
points(2,:)+points(3,:)-points(1,:);points(3,:)], trans_mat);
6+
end
7+

create_surface.m

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
function [ X, Y, Z, C ] = create_surface( points, trans_mat )
2+
%CREATE_SURFACE Summary of this function goes here
3+
% Detailed explanation goes here
4+
5+
points = points*trans_mat;
6+
X = [points(:,1)',points(1,1)];
7+
Y = [points(:,2)',points(1,2)];
8+
Z = [points(:,3)',points(1,3)];
9+
C = sqrt(pow2(Z)+pow2(Y)+pow2(X));
10+
end
11+

frames.m

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
function [ fs ] = frames( varargin )
2+
%FRAMES 将输入资源转换为frame数据组
3+
% fs = frames(...)
4+
% 输入可以为图片文件路径、FIG文件路径、图片数据和frame影片数据
5+
len = length(varargin);
6+
fs = struct('cdata',num2cell(zeros(1,len,'uint8')),'colormap',num2cell(zeros(1,len,'double')));
7+
for i=1:len
8+
e = varargin{1,i};
9+
switch(class(e))
10+
case 'char'
11+
filename = strsplit(e,'.');
12+
fmt = upper(filename{end});
13+
try
14+
switch(fmt)
15+
case {'PNG','JPG','JPEG','BMP'}
16+
fs(1,i) = im2frame(imread(e));
17+
case {'FIG'}
18+
open(e);
19+
fs(1,i) = getframe;
20+
close gcf;
21+
otherwise
22+
warning(['filetype ' fmt ' not surpported !']);
23+
end
24+
catch
25+
warning(['resource "' e '" load failed ![INDEX ' num2str(i) ']']);
26+
end
27+
case 'struct'
28+
fs(1,i) = e;
29+
case 'uint8'
30+
try
31+
fs(1,i) = im2frame(e);
32+
catch
33+
warning(['imdata load failed !' '[INDEX ' num2str(i) ']']);
34+
end
35+
end
36+
end
37+
end

get_rl.m

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
function [ rl_tm ] = get_rl( pl_tm )
2+
%GET_RL Get Reciprocal Lattice from Positive crystal lattice
3+
%transformation matrix.
4+
% RL_TM = GET_RL( PL_TM )
5+
% argsin:
6+
% pl_tm Positive crystal lattice transformation matrix.
7+
% argsout:
8+
% rl_tm Reciprocal Lattice transformation matrix.
9+
10+
rl_tm(1,:) = 2*pi*cross(pl_tm(2,:), pl_tm(3,:))/dot(pl_tm(1,:), cross(pl_tm(2,:), pl_tm(3,:)));
11+
rl_tm(2,:) = 2*pi*cross(pl_tm(3,:), pl_tm(1,:))/dot(pl_tm(2,:), cross(pl_tm(3,:), pl_tm(1,:)));
12+
rl_tm(3,:) = 2*pi*cross(pl_tm(1,:), pl_tm(2,:))/dot(pl_tm(3,:), cross(pl_tm(1,:), pl_tm(2,:)));
13+
end
14+

get_surface_symmetry_point.m

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
function [ s ] = get_surface_symmetry_point( o, surface )
2+
%GET_SURFACE_SYMMETRY_POINT Summary of this function goes here
3+
% Detailed explanation goes here
4+
5+
a = surface(1,:);
6+
b = surface(2,:);
7+
v_ao = o-a;
8+
v_ab = a-b;
9+
l_ap = dot(v_ao,v_ab)/norm(v_ab);
10+
v_ap = l_ap*v_ab/norm(v_ab);
11+
v_as = v_ao-2*v_ap;
12+
s = v_as+a;
13+
end
14+

get_surface_symmetry_points.m

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
function [ sps ] = get_surface_symmetry_points( points, surface )
2+
%GET_SURFACE_SYMMETRY_POINTS Summary of this function goes here
3+
% Detailed explanation goes here
4+
5+
count = 0;
6+
sps = zeros(size(points));
7+
for o = points'
8+
count = count + 1;
9+
sps(count,:) = get_surface_symmetry_point(o', surface);
10+
end
11+
end
12+

get_symmetry_point.m

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
function [ s ] = get_symmetry_point( o, line )
2+
%GET_SYMMETRY_POINT Summary of this function goes here
3+
% Detailed explanation goes here
4+
5+
a = line(1,:);
6+
b = line(2,:);
7+
v_ab = b-a;
8+
v_ao = o-a;
9+
l_ap = dot(v_ao,v_ab)/norm(v_ab);
10+
v_ap = l_ap*v_ab/norm(v_ab);
11+
v_po = v_ao-v_ap;
12+
v_as = v_ao-2*v_po;
13+
s = v_as + a;
14+
end
15+

get_symmetry_points.m

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
function [ sps ] = get_symmetry_points( points, line )
2+
%GET_SYMMETRY_POINTS Summary of this function goes here
3+
% Detailed explanation goes here
4+
5+
count = 0;
6+
sps = zeros(size(points));
7+
for o = points'
8+
count = count + 1;
9+
sps(count,:) = get_symmetry_point(o', line);
10+
end
11+
end
12+

gif/bcc_pl.gif

8.6 MB
Loading

gif/bcc_rl.gif

8.71 MB
Loading

gif/bcc_ws.gif

8.55 MB
Loading

gif/fcc_pl.gif

8.79 MB
Loading

gif/fcc_rl.gif

8.77 MB
Loading

gif/fcc_ws.gif

10.9 MB
Loading

gif/sc_pl.gif

8.05 MB
Loading

gif/sc_rl.gif

8.73 MB
Loading

gif/sc_ws.gif

10.5 MB
Loading

gif/sh_pl.gif

9.73 MB
Loading

gif/sh_rl.gif

9.31 MB
Loading

im2gif.m

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
function [ ] = im2gif( varargin )
2+
%IM2GIF 将图片数据集保存为GIF动图
3+
% IM2GIF(frames, filename, delay, size, n)
4+
% frames 影片数据组,格式为 1xn,每一个元素为{cdata,colormap}结构体
5+
% filename图片保存文件名
6+
% delay 图片合成间隔,单位秒(s)
7+
% size 图片尺寸size=[wight,height]
8+
% n 图片保存的颜色位数
9+
vlen = length(varargin);
10+
if vlen < 2
11+
error('number of arguments error !');
12+
else
13+
frames = varargin{1,1};
14+
filename = varargin{1,2};
15+
% 默认参数配置
16+
delay = .5;
17+
size = false;
18+
n = 32;
19+
if vlen >2
20+
delay = varargin{1,3};
21+
end
22+
if vlen > 3
23+
size = varargin{1,4};
24+
end
25+
if vlen > 4
26+
n = varargin{1,5};
27+
end
28+
end
29+
30+
flen = length(frames);
31+
if flen < 2
32+
warning('No dynamic photo created: frames too less !');
33+
end
34+
for i=1:flen
35+
im = frame2im(frames(1,i));
36+
% 改变图片尺寸
37+
if size~=false
38+
im = imresize(im, fliplr(size));
39+
end
40+
% 转换数据格式
41+
[I,map] = rgb2ind(im, n);
42+
if i==1
43+
imwrite(I,map,filename, 'gif', 'Loopcount', inf, 'DelayTime', delay);
44+
else
45+
imwrite(I,map,filename, 'gif', 'WriteMode', 'append', 'DelayTime', delay);
46+
end
47+
end
48+
end

0 commit comments

Comments
 (0)