此刻,我很困惑,建议在开发代码时遇到一些缺陷。 我正在尝试实现一个函数,该函数可计算出以下角度和距离(距离=观察者到刀片的距离),如图所示: 这些值是转子的一个叶片部分的值。最终目标是具有一种功能,该功能需要转子的观察者位置和轮毂位置,然后为转子叶片的一整圈旋转计算所有段的所有角度和距离。 下面是我想出的代码。 如果我的代码正确与否,如果有人可以给我任何提示,那将是极大的帮助!顺便说一句,有没有更容易/更快的方法? 提前非常感谢!
clc
clear all
close all
% Number of rotation increments
userInput.azNum = 8;
% Number of blade segments
userInput.segNum = 20;
% Airfoil chords per segment
userInput.c = [0.121 0.121 0.121 0.121 0.121 0.121 0.121 0.121 0.121 0.121 0.121 0.121 0.121 0.121 0.121 0.121 0.121 0.121 0.121 0.121];
% Airfoil's radial distance per segment
userInput.distRad = [0.440;0.520;0.600;0.680;0.760;0.840;0.920;1;1.08;1.16;1.24;1.32;1.40;1.48;1.56;1.64;1.72;1.80;1.88;1.96]';
% Observer position
userInput.xObsG = 0;
userInput.yObsG = 0;
userInput.zObsG = 0;
% Rotorhub position
userInput.xRothubG = 0;
userInput.yRothubG = 0;
userInput.zRothubG = 2;
% Intialise vectors
userInput.r = zeros(userInput.segNum,userInput.azNum);
userInput.phi = zeros(userInput.segNum,userInput.azNum);
userInput.theta = zeros(userInput.segNum,userInput.azNum);
% Compute angles for a complete revolution and get the distance to each
% trailing edge segment and the needed angles
for i =1:1:userInput.azNum
userInput.psi(i) = i*2*pi/userInput.azNum;
[~,userInput.r(:,i),userInput.phi(:,i),userInput.theta(:,i)] = ...
DirectComp(userInput.xObsG,userInput.yObsG,userInput.zObsG,userInput.xRothubG,userInput.yRothubG,userInput.zRothubG,userInput.c,userInput.distRad,userInput.psi(i));
end
% Plot results
figure(30)
subplot(3,1,1)
plot(rad2deg(userInput.psi),userInput.r,'*-')
subplot(3,1,2)
plot(rad2deg(userInput.psi),rad2deg(userInput.theta),'*-')
subplot(3,1,3)
plot(rad2deg(userInput.psi),rad2deg(userInput.phi),'*-')
% Actual function
function [r,r_norm,phi,theta] = DirectComp(xObsG,yObsG,zObsG,xRothubG,yRothubG,zRothubG,chord,distRad,psi)
for d = 1:1:length(distRad)
% Observer vector in global coordinate system
observerVector_global = [xObsG,yObsG,zObsG];
% Hub vector in global coordinate system
hubVector_global = [xRothubG,yRothubG,zRothubG];
% Observer vector in hub coordinate system
observerVector_hub = -observerVector_global + hubVector_global;
% Blade vector at psi = 0 in hub coordinate system
bladeVectorStart_hub = [chord(d)/2, distRad(d),observerVector_global(3)];
% x vector at beta = 0, in hub coordinate system
xStart_hub = [0,1,0];
% Blade and x vector in function of beta
v1 = bladeVectorStart_hub(1)*cos(psi) - bladeVectorStart_hub(2)*sin(psi);
v2 = bladeVectorStart_hub(1)*sin(psi) + bladeVectorStart_hub(2)*cos(psi);
v3 = bladeVectorStart_hub(3);
x1 = xStart_hub(1)*cos(psi) - xStart_hub(2)*sin(psi);
x2 = xStart_hub(1)*sin(psi) + xStart_hub(2)*cos(psi);
x3 = xStart_hub(3);
x = [x1,x2,x3];
bladeVector_hub = [v1,v2,v3];
% Vector from blade to observer in hub coordinate system
r(d,:) = observerVector_hub - bladeVector_hub;
r_norm(d) = norm(r(d,:));
% theta
theta(d) = atan2(norm(cross(r(d,:),x)), dot(r(d,:),x))';
% phi
n = cross(r(d,:),x); % vector perpendicular to r and x
z = [0,0,1];
phi(d) = atan2(norm(cross(z,n)), dot(z,n))';
end
end