-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwingrotation2.m
181 lines (148 loc) · 4.47 KB
/
wingrotation2.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
function[lattice]=wingrotation2(wingno,geo,lattice,Raxle,hinge_pos,alpha)
%%%
% This function is a part of TORNADO, the vortex lattice method.
%
% wingrotation2 rotates the lattice of a wing according to user input.
% This might be used if the incidence of an entire wing changes, as would
% be the case with tailerons, all-moving canards, and other suchlike.
%
% WINGROTATION2(WINGNO,GEO,LATTICE,RAXLE,HINGE_POS,ALPHA) rotates wing
% number WINGNO, ALPHA radians around the rotaion axis RAXLE, with the
% origin in HINGE_POS.
%
% GEO and LATTICE are the standard Tornado geometry data.
%
% Output is the new, rotated lattice to be used en the tornado solver.
%
%Example:
%
% [lattice,ref]=fLattice_setup(geo,state);
% geometryplot(lattice,geo,ref);
%
% Calls:
% None.
%
% Author: Tomas Melin <dr.tomas.melin@gmail.com>
% Keywords: Tornado text based user interface
%
% Revision History:
% Bristol, 2008 12 07: Function created. T.M.
% Spånga, 2021-09-19: Updated to MATLAB R2020, TM
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
lemma1=((geo.nx+geo.fnx).*geo.ny);
lemma2=(geo.symetric+1)';
[a b]=size(lemma1);
for i=1:b
npan_m1(:,i)=lemma1(:,i).*lemma2;
end
npan=sum(npan_m1,2);
if wingno==1;
startindex=1;
endindex=npan(1);
else
startindex_m1=cumsum(npan);
startindex=startindex_m1(wingno-1)+1;
endindex=startindex_m1(wingno);
end
%%Move to rotation centre
l.V(:,:,1)=lattice.VORTEX(startindex:endindex,:,1)-hinge_pos(1);
l.V(:,:,2)=lattice.VORTEX(startindex:endindex,:,2)-hinge_pos(2);
l.V(:,:,3)=lattice.VORTEX(startindex:endindex,:,3)-hinge_pos(3);
l.C(:,1)=lattice.COLLOC(startindex:endindex,1)-hinge_pos(1);
l.C(:,2)=lattice.COLLOC(startindex:endindex,2)-hinge_pos(2);
l.C(:,3)=lattice.COLLOC(startindex:endindex,3)-hinge_pos(3);
l.XYZ(:,:,1)=lattice.XYZ(startindex:endindex,:,1)-hinge_pos(1);
l.XYZ(:,:,2)=lattice.XYZ(startindex:endindex,:,2)-hinge_pos(2);
l.XYZ(:,:,3)=lattice.XYZ(startindex:endindex,:,3)-hinge_pos(3);
l.N(:,:,:)=lattice.N(startindex:endindex,:,:);
[ai bi ci]=size(l.V);
l2.C=trot4(Raxle,l.C,alpha)';
l2.N=trot4(Raxle,l.N,alpha)';
for i=2:(bi-1)
for j=1:ai;
A(j,:)=l.V(j,i,:);
end
B=trot4(Raxle,A,alpha)';
l2.V(:,i,:)=B;
end
l2.V(:,1,:)=l.V(:,1,:);
l2.V(:,bi,:)=l.V(:,bi,:);
for i=1:5
for j=1:ai;
A(j,:)=l.XYZ(j,i,:);
end
B=trot4(Raxle,A,alpha)';
l2.XYZ(:,i,:)=B;
end
%%Move back from rotation centre
l2.V(:,:,1)=l2.V(:,:,1)+hinge_pos(1);
l2.V(:,:,2)=l2.V(:,:,2)+hinge_pos(2);
l2.V(:,:,3)=l2.V(:,:,3)+hinge_pos(3);
l2.C(:,1)=l2.C(:,1)+hinge_pos(1);
l2.C(:,2)=l2.C(:,2)+hinge_pos(2);
l2.C(:,3)=l2.C(:,3)+hinge_pos(3);
l2.XYZ(:,:,1)=l2.XYZ(:,:,1)+hinge_pos(1);
l2.XYZ(:,:,2)=l2.XYZ(:,:,2)+hinge_pos(2);
l2.XYZ(:,:,3)=l2.XYZ(:,:,3)+hinge_pos(3);
lattice.VORTEX(startindex:endindex,:,:)=l2.V;
lattice.COLLOC(startindex:endindex,:,:)=l2.C;
lattice.XYZ(startindex:endindex,:,:)=l2.XYZ;
lattice.N(startindex:endindex,:,:)=l2.N;
end%function wingrotation
function[p2]=trot4(hinge,p,alpha)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% TROT: Auxillary rotation function
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% rotates point p around hinge alpha rads.%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ref: Råde, Westergren, BETA 4th ed,
% studentlitteratur, 1998
% pp:107-108
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Author: Tomas Melin, KTH,Department of%
% aeronautics, Copyright 2000
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Context: Auxillary function for
% TORNADO.
% Called by: setrudder, normals
% Calls: norm (MATLAB std fcn)
% sin "
% cos "
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% HELP: Hinge=vector around rotation
% takes place.
% p=point to be rotated
% alpha=radians of rotation
% 3D-workspace
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a=hinge(1);
b=hinge(2);
c=hinge(3);
rho=sqrt(a^2+b^2);
r=sqrt(a^2+b^2+c^2);
if r==0
cost=0
sint=1;
else
cost=c/r;
sint=rho/r;
end
if rho==0
cosf=0;
sinf=1;
else
cosf=a/rho;
sinf=b/rho;
end
cosa=cos(alpha);
sina=sin(alpha);
RZF=[[cosf -sinf 0];[sinf cosf 0];[0 0 1]];
RYT=[[cost 0 sint];[0 1 0];[-sint 0 cost]];
RZA=[[cosa -sina 0];[sina cosa 0];[0 0 1]];
RYMT=[[cost 0 -sint];[0 1 0];[sint 0 cost]];
RZMF=[[cosf sinf 0];[-sinf cosf 0];[0 0 1]];
P=RZF*RYT*RZA*RYMT*RZMF;
p2=P*p';
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
end%function wingrotation