-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhexagon.m
82 lines (68 loc) · 1.87 KB
/
hexagon.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
function hex = hexagon(x,y,th,scale,type)
% % Syntax;
% %
% % hex = hexagon(x,y,th,scale,type);
% %
% % ***********************************************************
% %
% % Description
% %
% % this program creates the hexagon of given configuration and size.
% %
% % ***********************************************************
% %
% % Input Variables
% %
% % x and y are the rectangular co-ordinates of the center of the hexagon
% % th is the rotation angle measured anticlockwise positive from positive
% % x axis
% % type veriable decides the type of hexagon as follows:
% % % type = 1 full hexagon.
% % % type = 2 half hexagon.
% % % type = 3 1/6 th hexagon.
% % ***********************************************************
% %
% % Output
% %
% % 3D plot of the Goldberg polyhedral shape.
% %
% % ***********************************************************
% %
% Example
%
% hex = hexagon(0,0,pi/6,0.5,1)
%
% hex =
%
% -0.2500 0.2500 0.5000 0.2500 -0.2500 -0.5000 -0.2500
% 0.4330 0.4330 0.0000 -0.4330 -0.4330 0.0000 0.4330
%
% % ***********************************************************
% %
% % List of Sub Programs
% %
% % ***********************************************************
% %
% % This program was written by Yogesh G. Phalak
% %
% % date May 2020
% %
% %
% % ***********************************************************
% %
% % Feel free to modify this code.
% %
% rotation matrx with scale
rot_mat = scale*[cos(th), -sin(th);
sin(th), cos(th)];
if type == 1
hex(1,:)= sin((0:6)*2*pi/6);
hex(2,:)= cos((0:6)*2*pi/6);
elseif type == 2
hex(1,:)= [3^0.5/2,3^0.5/2,0,-3^0.5/2,-3^0.5/2];
hex(2,:)= [0,0.5,1,0.5,0];
end
hex = rot_mat*hex;
hex(1,:)= x+hex(1,:);
hex(2,:)= y+hex(2,:);
end