-
Notifications
You must be signed in to change notification settings - Fork 0
/
plotStars.m
142 lines (119 loc) · 3 KB
/
plotStars.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
function [x0,nv] = plotStars
% draw the circle
close all;
% clear; clc;
x0 = 10000;
%x = -x0:x0;
%y1 = sqrt(x0^2-x.^2
%y2 = - sqrt(x0^2-x.^2);
% user settings
ratio = 0.5; % inner circle
nv = 12; % number of vertex points
[rxVec, ryVec,rx,ry,x,y1,y2,rx1,ry1] = plotStar(x0,ratio,nv);
% plot an inner star
ratio = 0.15;
[rxVec1, ryVec1] = plotStar(0.1*x0,ratio,nv);
% plot a circle on each line
r1 = x0/20;
xM = x0/3;
[rxMatrix,ry1Matrix,ry2Matrix] = getCircle(r1,nv,xM);
% 2nd circle on each line
r1 = x0/25; %15
xM = 2*x0/3;
[rxMatrix1,ry1Matrix1,ry2Matrix1] = getCircle(r1,nv,xM);
% Plot
figure(1)
plot(x,y1,'k-.',x,y2,'k--');
axis tight;
set(gcf, 'position',[360 149 523 523]);
hold on;
plot(rx,ry,'r*');
plot(rx1,ry1,'ro');
plot(rxVec,ryVec,'g-');
plot(rxVec1,ryVec1,'b-');
%
% for idx = 0: nv-1
% x1 = rxMatrix(idx +1,:);
% y1 = ry1Matrix(idx+1,:);
% y2 = ry2Matrix(idx+1,:);
% plot(x1,y1,'b',x1,y2,'b');
% end
% for idx = 0: nv-1
% x1 = rxMatrix1(idx +1,:);
% y1 = ry1Matrix1(idx+1,:);
% y2 = ry2Matrix1(idx+1,:);
% plot(x1,y1,'b',x1,y2,'b');
% end
hold off
hFig =figure(2);
plot(rxVec,ryVec,'k');
axis tight;
set(gcf, 'position',[360 149 523 523]);
hold on;
plot(rxVec1,ryVec1,'k');
for idx = 0: nv-1
x1 = rxMatrix(idx +1,:);
y1 = ry1Matrix(idx+1,:);
y2 = ry2Matrix(idx+1,:);
plot(x1,y1,'k',x1,y2,'k');
end
for idx = 0: nv-1
x1 = rxMatrix1(idx +1,:);
y1 = ry1Matrix1(idx+1,:);
y2 = ry2Matrix1(idx+1,:);
plot(x1,y1,'k',x1,y2,'k');
end
set(gca,'YColor',[1,1,1])
set(gca,'XColor',[1,1,1])
set(gca,'Color',[1,1,1])
ax = gca;
ax.XAxis.Visible = 'off';
ax.YAxis.Visible = 'off';
hold off
saveas(hFig,'sternchen.pdf')
saveas(hFig,'sternchen.png')
saveas(hFig,'sternchen.eps')
%% subfunctions
function [rxVec, ryVec,rx,ry,x,y1,y2,rx1,ry1] = plotStar(x0,ratio,nv)
% draw the vertex points
offset = 0;
[rx,ry] = getStar(x0,nv,offset);
% plot inner circle
x0 = ratio * 10000;
x = -x0:x0;
y1 = sqrt(x0^2-x.^2);
y2 = - sqrt(x0^2-x.^2);
offset = pi/nv;
[rx1,ry1] = getStar(x0,nv,offset);
% connest inner and out points
rxAll = [rx';rx1'];
ryAll = [ry';ry1'];
rxVec = [rxAll(:);rxAll(1)];
ryVec = [ryAll(:);ryAll(1)];
function [rx,ry] = getStar(x0,nv,offset)
rx = nan(nv,1);
ry = nan(nv,1);
for idx = 0: nv-1
aAlpha = idx * 2*pi/nv + offset;
rx(idx+1) = x0* cos(aAlpha);
ry(idx+1) = x0* sin(aAlpha);
end
function [rxMatrix,ry1Matrix,ry2Matrix] = getCircle(r1,nv,xM)
x1a = (-r1:r1);
x1 = x1a + xM;
y1 = sqrt(r1^2 - (x1a).^2);
y2 = -sqrt(r1^2 - (x1a).^2);
ln = length(x1);
rxM = nan(nv,1);
ryM = nan(nv,1);
rxMatrix = nan(nv,ln);
ry1Matrix = nan(nv,ln);
ry2Matrix = nan(nv,ln);
for idx = 0: nv-1
aAlpha = idx * 2*pi/nv;
rxM(idx+1) = xM* cos(aAlpha);
ryM(idx+1) = xM* sin(aAlpha);
rxMatrix(idx +1,:) = x1a' + rxM(idx+1);
ry1Matrix(idx+1,:) = y1' + ryM(idx+1);
ry2Matrix(idx+1,:) = y2' + ryM(idx+1);
end